diff --git a/packages/api/src/resolvers/queries/users/users.ts b/packages/api/src/resolvers/queries/users/users.ts index 8b6e17d2cb..cdf3005608 100644 --- a/packages/api/src/resolvers/queries/users/users.ts +++ b/packages/api/src/resolvers/queries/users/users.ts @@ -1,5 +1,6 @@ import { log } from '@unchainedshop/logger'; import { Context, Root, SortOption } from '@unchainedshop/types/api.js'; +import { DateFilterInput } from '@unchainedshop/types/common.js'; import { UserQuery } from '@unchainedshop/types/user.js'; export default async function users( @@ -9,6 +10,8 @@ export default async function users( offset?: number; sort?: Array; includeGuests?: boolean; + emailVerified?: boolean; + lastLogin?: DateFilterInput; }, { modules, userId }: Context, ) { diff --git a/packages/core-users/src/module/configureUsersModule.ts b/packages/core-users/src/module/configureUsersModule.ts index efd3f86516..85d67d96c3 100644 --- a/packages/core-users/src/module/configureUsersModule.ts +++ b/packages/core-users/src/module/configureUsersModule.ts @@ -33,8 +33,8 @@ export const removeConfidentialServiceHashes = (rawUser: User): User => { export const buildFindSelector = ({ includeGuests, queryString, - emailVerified = null, - lastLogin = {}, + emailVerified, + lastLogin, ...rest }: UserQuery) => { const selector: mongodb.Filter = { ...rest, deleted: null }; @@ -43,13 +43,18 @@ export const buildFindSelector = ({ selector['emails.verified'] = true; } if (emailVerified === false) { - selector['emails.verified'] = false; + // We need to use $ne here else we'd also find users with many emails where one is + // unverified + selector['emails.verified'] = { $ne: true }; + } + if (lastLogin?.start) { + selector['lastLogin.timestamp'] = { $exists: true }; } if (lastLogin?.end) { - selector['lastLogin.timestamp'] = { $lte: lastLogin?.end }; + selector['lastLogin.timestamp'].$lte = new Date(lastLogin.end); } if (lastLogin?.start) { - selector['lastLogin.timestamp'] = { $gte: lastLogin?.start }; + selector['lastLogin.timestamp'].$gte = new Date(lastLogin.start); } if (queryString) { (selector as any).$text = { $search: queryString };