@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user