40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import {
|
|
getModelForClass,
|
|
index,
|
|
modelOptions,
|
|
mongoose,
|
|
plugin,
|
|
prop
|
|
} from '@typegoose/typegoose';
|
|
import {dbconn} from '../decorators/dbconn';
|
|
// @ts-ignore
|
|
import findOrCreate from 'mongoose-findorcreate';
|
|
import {
|
|
Base,
|
|
FindOrCreate,
|
|
TimeStamps
|
|
} from "@typegoose/typegoose/lib/defaultClasses";
|
|
import {Severity} from "@typegoose/typegoose/lib/internal/constants";
|
|
|
|
interface ActivityDataClass extends Base, TimeStamps {}
|
|
@dbconn()
|
|
@index({ accountId: 1, appId: 1}, { unique: true })
|
|
@plugin(findOrCreate)
|
|
@modelOptions({schemaOptions: {collection: "activity_data", timestamps: true}, options: {allowMixed: Severity.ALLOW}})
|
|
class ActivityDataClass extends FindOrCreate{
|
|
@prop()
|
|
public accountId: string;
|
|
@prop()
|
|
public appId: string;
|
|
@prop()
|
|
public nickname: string;
|
|
@prop()
|
|
public avatar: string;
|
|
@prop({type: mongoose.Schema.Types.Mixed})
|
|
public data: {};
|
|
@prop()
|
|
public comment?: string;
|
|
}
|
|
|
|
export const ActivityData = getModelForClass(ActivityDataClass, {existingConnection: ActivityDataClass['db']});
|