diff --git a/apps/core/src/constants/db.constant.ts b/apps/core/src/constants/db.constant.ts index 7430742a..374bb535 100644 --- a/apps/core/src/constants/db.constant.ts +++ b/apps/core/src/constants/db.constant.ts @@ -15,6 +15,7 @@ export const RECENTLY_COLLECTION_NAME = 'recentlies' export const ANALYZE_COLLECTION_NAME = 'analyzes' export const WEBHOOK_EVENT_COLLECTION_NAME = 'webhook_events' +export const USER_COLLECTION_NAME = 'users' export enum CollectionRefTypes { Post = POST_COLLECTION_NAME, Note = NOTE_COLLECTION_NAME, diff --git a/apps/core/src/modules/user/user.model.ts b/apps/core/src/modules/user/user.model.ts index 79095351..17dea0fb 100644 --- a/apps/core/src/modules/user/user.model.ts +++ b/apps/core/src/modules/user/user.model.ts @@ -5,6 +5,7 @@ import type { DocumentType } from '@typegoose/typegoose' import { modelOptions, prop, Severity } from '@typegoose/typegoose' +import { USER_COLLECTION_NAME } from '~/constants/db.constant' import { BaseModel } from '~/shared/model/base.model' export type UserDocument = DocumentType @@ -38,7 +39,9 @@ const securityKeys = [ 'lastLoginIp', 'password', ] as const -@modelOptions({ options: { customName: 'User', allowMixed: Severity.ALLOW } }) +@modelOptions({ + options: { customName: USER_COLLECTION_NAME, allowMixed: Severity.ALLOW }, +}) export class UserModel extends BaseModel { @prop({ required: true, unique: true, trim: true }) username!: string diff --git a/apps/core/src/utils/check-init.util.ts b/apps/core/src/utils/check-init.util.ts index 18d8c026..27752d16 100644 --- a/apps/core/src/utils/check-init.util.ts +++ b/apps/core/src/utils/check-init.util.ts @@ -1,9 +1,12 @@ +import { USER_COLLECTION_NAME } from '~/constants/db.constant' + import { getDatabaseConnection } from './database.util' export const checkInit = async () => { const connection = await getDatabaseConnection() const db = connection.db - const isUserExist = (await db.collection('users').countDocuments()) > 0 + const isUserExist = + (await db.collection(USER_COLLECTION_NAME).countDocuments()) > 0 return isUserExist }