/
todo.js
62 lines (51 loc) · 1.48 KB
/
todo.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
58
59
60
61
62
const keystone = require("keystone-nestedlist");
const Types = keystone.Field.Types;
/**
* Todo Model
* ==========
*/
const Task = new keystone.List("Task");
Task.add({
name: { type: Types.Text },
task: { type: Types.Text },
createdAt: { type: Types.Datetime, default: Date.now, noedit: true },
dueDate: { type: Types.Datetime, default: Date.now },
completed: { type: Boolean }
});
const Todo = new keystone.List("Todo");
Todo.add({
title: { type: Types.Text },
completed: { type: Boolean },
tasks: {
type: Types.List,
fields: {
name: { type: Types.Text },
task: { type: Types.Text },
createdAt: { type: Types.Datetime, default: Date.now, noedit: true },
dueDate: { type: Types.Datetime, default: Date.now },
completed: { type: Boolean }
},
},
device: { type: Types.Relationship, ref: "Device", require: true },
client: { type: Types.Relationship, ref: "Client", require: true },
createdAt: { type: Types.Datetime, default: Date.now, noedit: true },
});
Todo.schema.add({
tasks: [Task.schema],
});
// For whatever reason here you cannot use the arrow syntax if you want
// to get a reference to the current item to be saved.
// Thus we use the conventional syntax!
Todo.schema.pre("save", function (next, done) {
this.isUpdate = !this.isNew;
next();
});
/**
* Relationships
*/
/**
* Registration
*/
Todo.defaultColumns = "name, device, client, date, total";
Todo.register()
module.exports = Todo