fix: user collection name

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei
2024-04-15 20:16:23 +08:00
parent 8f9523dacf
commit 85ca2f64b4
3 changed files with 9 additions and 2 deletions

View File

@@ -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,

View File

@@ -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<UserModel>
@@ -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

View File

@@ -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
}