This repository has been archived by the owner on Jan 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
knowledgebase.ts
110 lines (94 loc) · 2.48 KB
/
knowledgebase.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { Document, Schema } from 'mongoose';
import { PUBLISH_STATUSES } from './constants';
import { field, schemaWrapper } from './utils';
interface ICommonFields {
createdBy: string;
createdDate: Date;
modifiedBy: string;
modifiedDate: Date;
}
export interface IArticle {
title?: string;
summary?: string;
content?: string;
status?: string;
reactionChoices?: string[];
reactionCounts?: { [key: string]: number };
}
export interface IArticleDocument extends ICommonFields, IArticle, Document {
_id: string;
}
export interface ICategory {
title?: string;
description?: string;
articleIds?: string[];
icon?: string;
}
export interface ICategoryDocument extends ICommonFields, ICategory, Document {
_id: string;
}
export interface ITopic {
title?: string;
description?: string;
brandId?: string;
categoryIds?: string[];
color?: string;
backgroundImage?: string;
languageCode?: string;
}
export interface ITopicDocument extends ICommonFields, ITopic, Document {
_id: string;
}
// Mongoose schemas ==================
// Schema for common fields
const commonFields = {
createdBy: field({ type: String }),
createdDate: field({
type: Date,
}),
modifiedBy: field({ type: String }),
modifiedDate: field({
type: Date,
}),
};
export const articleSchema = new Schema({
_id: field({ pkey: true }),
title: field({ type: String }),
summary: field({ type: String, optional: true }),
content: field({ type: String }),
status: field({
type: String,
enum: PUBLISH_STATUSES.ALL,
default: PUBLISH_STATUSES.DRAFT,
}),
reactionChoices: field({ type: [String], default: [] }),
reactionCounts: field({ type: Object }),
...commonFields,
});
export const categorySchema = new Schema({
_id: field({ pkey: true }),
title: field({ type: String }),
description: field({ type: String, optional: true }),
articleIds: field({ type: [String] }),
icon: field({ type: String, optional: true }),
...commonFields,
});
export const topicSchema = schemaWrapper(
new Schema({
_id: field({ pkey: true }),
title: field({ type: String }),
description: field({ type: String, optional: true }),
brandId: field({ type: String, optional: true }),
categoryIds: field({
type: [String],
required: false,
}),
color: field({ type: String, optional: true }),
backgroundImage: field({ type: String, optional: true }),
languageCode: field({
type: String,
optional: true,
}),
...commonFields,
}),
);