UserModel.ts 1001 Bytes
Newer Older
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
1
import { arrayProp, getModelForClass, index, prop, Severity } from '@typegoose/typegoose';
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
2
import DbDAO from '../../db/DbDAO';
3
import { DbCollection } from '../../enums/DbOperation';
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
4 5 6
import { IUserSerialized } from '../../interfaces/users/IUserSerialized';

@index({ name: 1 }, { unique: true })
7
export class UserModelItem implements IUserSerialized {
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
8
  @prop({ required: true }) public name: string;
9 10
  @prop({ required: false }) public passwordHash: string;
  @prop({ required: false }) public tokenHash: string;
11 12 13 14
  @arrayProp({
    required: true,
    items: String,
  }) public userAuthorizations: Array<string>;
15
  @prop({ required: true }) public privateKey: string;
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
16 17 18 19
  @prop() public gitlabToken?: string;
  @prop() public token?: string;
}

20
export const UserModel = getModelForClass(UserModelItem, {
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
21 22 23 24 25
  schemaOptions: {
    collection: DbCollection.Users,
    timestamps: true,
  },
  existingConnection: DbDAO.dbCon,
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
26 27 28 29
  options: {
    runSyncIndexes: true,
    allowMixed: Severity.ALLOW,
  },
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
30
});