Browse Source

feat: Add basic news schema

Owen Diffey 11 months ago
parent
commit
e5aa6549bf
3 changed files with 50 additions and 1 deletions
  1. 1 1
      backend/src/modules/DataModule.ts
  2. 47 0
      backend/src/schemas/news.ts
  3. 2 0
      backend/src/types/Models.ts

+ 1 - 1
backend/src/modules/DataModule.ts

@@ -133,7 +133,7 @@ export default class DataModule extends BaseModule {
 	private async loadModels() {
 		this.models = {
 			abc: await this.loadModel("abc"),
-			//			station: await this.loadModel("station")
+			news: await this.loadModel("news"),
 			station: await this.loadModel("station")
 		};
 	}

+ 47 - 0
backend/src/schemas/news.ts

@@ -0,0 +1,47 @@
+import { Schema, SchemaTypes, Types } from "mongoose";
+
+export enum NewsStatus {
+	DRAFT = "draft",
+	PUBLISHED = "published",
+	ARCHIVED = "archived"
+}
+
+export interface NewsSchema {
+	title: string;
+	markdown: string;
+	status: NewsStatus;
+	showToNewUsers: boolean;
+	createdBy: Types.ObjectId;
+	createdAt: NativeDate;
+}
+
+export const schema = new Schema<NewsSchema>({
+	title: {
+		type: SchemaTypes.String,
+		required: true
+	},
+	markdown: {
+		type: SchemaTypes.String,
+		required: true
+	},
+	status: {
+		type: SchemaTypes.String,
+		enum: Object.values(NewsStatus),
+		default: NewsStatus.DRAFT,
+		required: true
+	},
+	showToNewUsers: {
+		type: SchemaTypes.Boolean,
+		default: false,
+		required: true
+	},
+	createdBy: {
+		type: SchemaTypes.ObjectId,
+		required: true
+	},
+	createdAt: {
+		type: SchemaTypes.Date,
+		default: Date.now,
+		required: true
+	}
+});

+ 2 - 0
backend/src/types/Models.ts

@@ -1,9 +1,11 @@
 import { Model, InferSchemaType, Schema } from "mongoose";
 import { AbcSchema } from "../schemas/abc";
+import { NewsSchema } from "../schemas/news";
 import { StationSchema } from "../schemas/station";
 
 export type Schemas = {
 	abc: Schema<AbcSchema>;
+	news: Schema<NewsSchema>;
 	station: Schema<StationSchema>;
 };