Commit 84abd56ce56f9b24d7c8144b401dfe5cfebdb0a8

Authored by ly525
1 parent fb0d694b

backend controller: create work entry

back-end/h5-api/api/work/models/Work.js
@@ -20,7 +20,7 @@ module.exports = { @@ -20,7 +20,7 @@ module.exports = {
20 // After fetching a value. 20 // After fetching a value.
21 // Fired after a `fetch` operation. 21 // Fired after a `fetch` operation.
22 // afterFetch: async (model, response, options) => {}, 22 // afterFetch: async (model, response, options) => {},
23 - 23 +
24 // Before fetching all values. 24 // Before fetching all values.
25 // Fired before a `fetchAll` operation. 25 // Fired before a `fetchAll` operation.
26 // beforeFetchAll: async (model, columns, options) => {}, 26 // beforeFetchAll: async (model, columns, options) => {},
@@ -31,7 +31,12 @@ module.exports = { @@ -31,7 +31,12 @@ module.exports = {
31 31
32 // Before creating a value. 32 // Before creating a value.
33 // Fired before an `insert` query. 33 // Fired before an `insert` query.
34 - // beforeCreate: async (model, attrs, options) => {}, 34 + beforeCreate: async (model, attrs, options) => {
  35 + const defaultPages = [{
  36 + elements: []
  37 + }];
  38 + model.set('pages', JSON.stringify(defaultPages));
  39 + },
35 40
36 // After creating a value. 41 // After creating a value.
37 // Fired after an `insert` query. 42 // Fired after an `insert` query.
back-end/h5-api/api/work/models/Work.settings.json
@@ -16,10 +16,12 @@ @@ -16,10 +16,12 @@
16 "attributes": { 16 "attributes": {
17 "title": { 17 "title": {
18 "required": true, 18 "required": true,
19 - "type": "string" 19 + "type": "string",
  20 + "default": "default title"
20 }, 21 },
21 "description": { 22 "description": {
22 - "type": "text" 23 + "type": "text",
  24 + "default": "default desc"
23 }, 25 },
24 "cover_image_url": { 26 "cover_image_url": {
25 "type": "string" 27 "type": "string"