Work.js
2.46 KB
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
'use strict';
/**
* Lifecycle callbacks for the `Work` model.
*/
module.exports = {
// Before saving a value.
// Fired before an `insert` or `update` query.
// beforeSave: async (model, attrs, options) => {
// // https://github.com/strapi/strapi/issues/2882
// // need to remove this after this pr will be merged(https://github.com/strapi/strapi/pull/3664)
// Object.keys(model.constructor.attributes).forEach(k => {
// if (model.constructor.attributes[k].type === 'json') {
// const value = model.get(k);
// if (Array.isArray(value)) {
// model.set(k, JSON.stringify(value));
// }
// }
// });
// },
// After saving a value.
// Fired after an `insert` or `update` query.
// afterSave: async (model, response, options) => {},
// Before fetching a value.
// Fired before a `fetch` operation.
// beforeFetch: async (model, columns, options) => {},
// After fetching a value.
// Fired after a `fetch` operation.
// afterFetch: async (model, response, options) => {},
// Before fetching all values.
// Fired before a `fetchAll` operation.
// beforeFetchAll: async (model, columns, options) => {},
// After fetching all values.
// Fired after a `fetchAll` operation.
// afterFetchAll: async (model, response, options) => {},
// Before creating a value.
// Fired before an `insert` query.
beforeCreate: async (model, attrs, options) => {
const defaultPages = [{
elements: []
}];
model.set('pages', JSON.stringify(defaultPages));
model.set('is_template', false);
},
// After creating a value.
// Fired after an `insert` query.
// afterCreate: async (model, attrs, options) => {},
// Before updating a value.
// Fired before an `update` query.
// beforeUpdate: async (model, attrs, options) => {
// Object.keys(model.constructor.attributes).forEach(k => {
// if (model.constructor.attributes[k].type === 'json') {
// const value = model.get(k);
// if (Array.isArray(value)) {
// model.set(k, JSON.stringify(value));
// }
// }
// });
// },
// After updating a value.
// Fired after an `update` query.
// afterUpdate: async (model, attrs, options) => {},
// Before destroying a value.
// Fired before a `delete` query.
// beforeDestroy: async (model, attrs, options) => {},
// After destroying a value.
// Fired after a `delete` query.
// afterDestroy: async (model, attrs, options) => {}
};