-
Notifications
You must be signed in to change notification settings - Fork 3
/
species-model.js
57 lines (54 loc) · 1.13 KB
/
species-model.js
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
const mongoose = require('mongoose');
const utils = require('../../common/utils');
const SpeciesCode = require('../const/species-code');
const { Schema } = mongoose;
utils.connectDatabase();
const model = mongoose.model(
'SpeciesModel',
utils.generateSchema(
{
project: {
type: Schema.ObjectId,
ref: 'ProjectModel',
required: true,
index: {
name: 'Project',
},
},
title: {
// 物種名稱
'zh-TW': {
// 繁體中文
type: String,
required: true,
index: {
// We will use species to search from .csv.
name: 'TitleZhTW',
},
},
},
index: {
// 排序 (由小到大)
type: Number,
default: 0,
},
code: {
// 供「提示定義」使用
type: String,
enum: SpeciesCode.all(),
},
},
{
collection: 'Species',
},
),
);
model.prototype.dump = function() {
return {
id: `${this._id}`,
title: this.title,
index: this.index,
code: this.code,
};
};
module.exports = model;