feat(db/models): add new challenge models

biffno, ficmas, and "gen" challenges
This commit is contained in:
parent c517db3361
commit eeb7a97d84
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C
3 changed files with 162 additions and 0 deletions

@ -0,0 +1,68 @@
import mongoose, {Schema, PopulatedDoc, Document, Model} from "mongoose";
import { IUser } from "../../models/user";
import SequenceFactory from "mongoose-sequence";
import { hasMigrated } from "../../lib/dbconfig";
const AutoIncrement = SequenceFactory(mongoose);
export interface IBiffno {
_id: number;
title: string;
description: string;
excerpt: string;
bands: number[];
tags: string[];
wordcount: number;
genre: string;
cover: string;
year: number;
author: PopulatedDoc<IUser & Document>
}
const biffnoschema = new mongoose.Schema<IBiffno>({
_id: {
type: Number
},
title: {
type: String,
default: ""
},
description: {
type: String,
default: ""
},
excerpt: {
type: String,
default: ""
},
bands: [{
type: Number,
ref: "Band"
}],
tags: [{
type: String
}],
wordcount: {
type: Number,
default: 0
},
genre: {
type: String
},
cover: {
type: String,
default: ""
},
year: {
type: Number,
default: 0
},
author: {
type: Number,
ref: "User"
}
});
hasMigrated && biffnoschema.plugin(AutoIncrement, {start_seq: 1, id: "bif_id"});
export const Biffno: Model<IBiffno> = /* mongoose.models.Biffno || */ mongoose.model('Biffno', biffnoschema, 'biffno');

@ -0,0 +1,45 @@
import mongoose, {Schema, PopulatedDoc, Document, Model, model} from "mongoose";
import { IBand } from "../../models/band";
import { IUser } from "../../models/user";
import SequenceFactory from "mongoose-sequence";
import { hasMigrated } from "../../lib/dbconfig";
const AutoIncrement = SequenceFactory(mongoose);
export interface IFicmas {
_id: number;
kink: string;
year: string;
bands: PopulatedDoc<IBand & Document>[];
relationship: string;
wisher: PopulatedDoc<IUser & Document>;
anniversary: boolean;
}
export const FicmasSchema = new mongoose.Schema<IFicmas>({
_id: {
type: Number
},
kink: {
type: String
},
year: { type: String },
bands: [{
type: Number,
ref: "Band"
}],
relationship: { type: String },
wisher: {
type: Number,
ref: "User"
},
anniversary: {
type: Boolean,
default: false
}
})
hasMigrated && FicmasSchema.plugin(AutoIncrement, {id: "ficmas_wishes"})
export const Ficmas: Model<IFicmas> = /* mongoose.models.Ficmas || */ model("Ficmas", FicmasSchema, "ficmas_wishes")

49
models/challenges/gen.ts Normal file

@ -0,0 +1,49 @@
import mongoose, {Schema, PopulatedDoc, Document, Model} from "mongoose";
import SequenceFactory from "mongoose-sequence";
import { hasMigrated } from "../../lib/dbconfig";
const AutoIncrement = SequenceFactory(mongoose);
export interface IChallenge {
_id: number;
name: string;
description: string;
deadline: Date;
active: boolean;
color: string;
allowMultiple: boolean;
}
const challengeSchema = new mongoose.Schema<IChallenge>({
_id: {
type: Number
},
name: {
type: String,
required: true
},
description: {
type: String,
required: true
},
deadline: {
type: Date,
required: true
},
active: {
type: Boolean,
default: true
},
color: {
type: String,
required: true,
default: `#${Math.floor(Math.random()*16777215).toString(16)}`
},
allowMultiple: {
type: Boolean,
default: true
}
})
hasMigrated && challengeSchema.plugin(AutoIncrement, {id: "challenges"});
export const Challenge: Model<IChallenge> = /* mongoose.models.Challenge || */ mongoose.model("Challenge", challengeSchema, "challenges")