larvituser
Advanced tools
Comparing version 0.24.8 to 0.25.0
@@ -10,4 +10,4 @@ import { LogInstance } from 'larvitutils'; | ||
passwordIsFalse: boolean; | ||
created?: string; | ||
updated?: string; | ||
created?: Date; | ||
updated?: Date; | ||
fields?: Record<string, string[]>; | ||
@@ -22,4 +22,4 @@ }; | ||
passwordIsFalse: boolean; | ||
created?: string; | ||
updated?: string; | ||
created?: Date; | ||
updated?: Date; | ||
fields: Record<string, string[]>; | ||
@@ -26,0 +26,0 @@ constructor(options: UserBaseOptions); |
import { LogInstance } from 'larvitutils'; | ||
export type matchDate = { | ||
field: string; | ||
value: string; | ||
operation?: 'gt' | 'lt' | 'eq'; | ||
}; | ||
export type UsersOptions = { | ||
@@ -8,9 +13,4 @@ db: any; | ||
showInactiveOnly?: boolean; | ||
matchDateFields?: [ | ||
{ | ||
field: string; | ||
value: string | Array<string>; | ||
operation?: 'gt' | 'lt' | 'eq'; | ||
} | ||
]; | ||
matchDateFields?: matchDate[]; | ||
matchDates?: matchDate[]; | ||
matchAllFields?: Record<string, string | Array<string>>; | ||
@@ -29,4 +29,4 @@ matchAllFieldsQ?: Record<string, string | Array<string>>; | ||
uuids?: string | string[]; | ||
createdAfter?: string; | ||
updatedAfter?: string; | ||
createdAfter?: Date; | ||
updatedAfter?: Date; | ||
}; | ||
@@ -33,0 +33,0 @@ export type UserFields = { |
@@ -33,2 +33,3 @@ "use strict"; | ||
const logPrefix = `${topLogPrefix} get() -`; | ||
const dbCon = await db.getConnection(); | ||
const dbFields = []; | ||
@@ -47,19 +48,29 @@ let sqlWhere = ''; | ||
if (options.createdAfter) { | ||
if (isNaN(Date.parse(options.createdAfter))) { | ||
sqlWhere += ' AND created IS NULL\n'; | ||
} | ||
else { | ||
sqlWhere += ' AND created >= ?\n'; | ||
dbFields.push(options.createdAfter); | ||
} | ||
sqlWhere += ' AND created >= ?\n'; | ||
dbFields.push(options.createdAfter); | ||
} | ||
// Check updatedAfter | ||
if (options.updatedAfter) { | ||
if (isNaN(Date.parse(options.updatedAfter))) { | ||
sqlWhere += ' AND created IS NULL\n'; | ||
sqlWhere += ' AND updated >= ?\n'; | ||
dbFields.push(options.updatedAfter); | ||
} | ||
// Check headerDates | ||
if (options.matchDates && options.matchDates.length) { | ||
for (const matchExistingDate of options.matchDates) { | ||
const operation = matchExistingDate.operation || 'eq'; | ||
const value = matchExistingDate.value; | ||
const field = matchExistingDate.field; | ||
if (!value) | ||
continue; | ||
if (!field) | ||
continue; | ||
sqlWhere += ' AND ' + dbCon.escapeId(field); | ||
if (operation === 'eq') | ||
sqlWhere += ' = CAST(? AS DATETIME)\n'; | ||
else if (operation === 'gt') | ||
sqlWhere += ' > CAST(? AS DATETIME)\n'; | ||
else if (operation === 'lt') | ||
sqlWhere += ' < CAST(? AS DATETIME)\n'; | ||
dbFields.push(value); | ||
} | ||
else { | ||
sqlWhere += ' AND updated >= ?\n'; | ||
dbFields.push(options.updatedAfter); | ||
} | ||
} | ||
@@ -191,3 +202,2 @@ // Build where-statement | ||
} | ||
const dbCon = await db.getConnection(); | ||
const mainDbFields = dbFields.slice(0); | ||
@@ -198,5 +208,5 @@ const returnFields = options.returnFields ? (0, helpers_1.arrayify)(options.returnFields) : undefined; | ||
if (options.order !== undefined && typeof options.order === 'object') { | ||
const allowedSortables = ['uuid', 'username', ...returnFields ?? []]; | ||
const allowedSortables = ['uuid', 'username', 'created', 'updated', ...returnFields ?? []]; | ||
if (options.order.by !== undefined && allowedSortables.includes(options.order.by)) { | ||
if (options.order.by !== 'uuid' && options.order.by !== 'username') { | ||
if (!['uuid', 'username', 'created', 'updated'].includes(options.order.by)) { | ||
sql += ', group_concat(user_users_data.data) as ' + dbCon.escapeId(options.order.by) + ' FROM user_users '; | ||
@@ -203,0 +213,0 @@ sql += 'LEFT JOIN user_users_data on (user_users_data.fieldUuid = (SELECT uuid FROM user_data_fields WHERE name = ?) AND user_users_data.userUuid = user_users.uuid) '; |
{ | ||
"name": "larvituser", | ||
"version": "0.24.8", | ||
"version": "0.25.0", | ||
"author": { | ||
@@ -5,0 +5,0 @@ "name": "Mikael 'Lilleman' Göransson", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
119231
1546