更新 src/models/guildModel.ts
This commit is contained in:
parent
cdb4032ba3
commit
ee9bf5b1a9
@ -5,6 +5,9 @@ import {
|
||||
ITechProjectClient,
|
||||
IDojoDecoDatabase,
|
||||
ILongMOTD,
|
||||
IGuildLogDatabase,
|
||||
IGuildLogItemDatabase,
|
||||
IGuildLogItemClient,
|
||||
IGuildMemberDatabase
|
||||
} from "@/src/types/guildTypes";
|
||||
import { Document, Model, model, Schema, Types } from "mongoose";
|
||||
@ -125,3 +128,62 @@ const guildMemberSchema = new Schema<IGuildMemberDatabase>({
|
||||
guildMemberSchema.index({ accountId: 1, guildId: 1 }, { unique: true });
|
||||
|
||||
export const GuildMember = model<IGuildMemberDatabase>("GuildMember", guildMemberSchema);
|
||||
|
||||
const guildLogItemSchema = new Schema<IGuildLogItemDatabase>(
|
||||
{
|
||||
dateTime: Date,
|
||||
entryType: Number,
|
||||
details: String
|
||||
},
|
||||
{ _id: false }
|
||||
);
|
||||
|
||||
guildLogItemSchema.set("toJSON", {
|
||||
virtuals: true,
|
||||
transform(_doc, obj) {
|
||||
const db = obj as IGuildLogItemDatabase;
|
||||
const client = obj as IGuildLogItemClient;
|
||||
if (db.dateTime) {
|
||||
client.dateTime = toMongoDate(db.dateTime);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const guildLogSchema = new Schema<IGuildLogDatabase>(
|
||||
{
|
||||
accountId: Types.ObjectId,
|
||||
guildId: Types.ObjectId,
|
||||
RoomChanges: [guildLogItemSchema],
|
||||
TechChanges: [guildLogItemSchema],
|
||||
RosterActivity: [guildLogItemSchema],
|
||||
StandingsUpdates: [guildLogItemSchema],
|
||||
ClassChanges: [guildLogItemSchema]
|
||||
},
|
||||
{ id: false }
|
||||
);
|
||||
|
||||
guildLogSchema.index({ accountId: 1, guildId: 1 }, { unique: true });
|
||||
|
||||
type GuildLogDocumentProps = {
|
||||
RoomChanges: Types.DocumentArray<IGuildLogItemDatabase>;
|
||||
TechChanges: Types.DocumentArray<IGuildLogItemDatabase>;
|
||||
RosterActivity: Types.DocumentArray<IGuildLogItemDatabase>;
|
||||
StandingsUpdates: Types.DocumentArray<IGuildLogItemDatabase>;
|
||||
ClassChanges: Types.DocumentArray<IGuildLogItemDatabase>;
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
type GuildLogModel = Model<IGuildLogDatabase, {}, GuildLogDocumentProps>;
|
||||
|
||||
export const GuildLog = model<IGuildLogDatabase, GuildLogModel>("GuildLog", guildLogSchema);
|
||||
|
||||
export type TGuildLogDatabaseDocument = Document<unknown, {}, IGuildLogDatabase> &
|
||||
Omit<
|
||||
IGuildLogDatabase & {
|
||||
_id: Types.ObjectId;
|
||||
} & {
|
||||
__v: number;
|
||||
},
|
||||
keyof GuildLogDocumentProps
|
||||
> &
|
||||
GuildLogDocumentProps;
|
Loading…
x
Reference in New Issue
Block a user