Commit 84abd56ce56f9b24d7c8144b401dfe5cfebdb0a8
1 parent
fb0d694b
backend controller: create work entry
Showing
2 changed files
with
11 additions
and
4 deletions
back-end/h5-api/api/work/models/Work.js
| ... | ... | @@ -20,7 +20,7 @@ module.exports = { |
| 20 | 20 | // After fetching a value. |
| 21 | 21 | // Fired after a `fetch` operation. |
| 22 | 22 | // afterFetch: async (model, response, options) => {}, |
| 23 | - | |
| 23 | + | |
| 24 | 24 | // Before fetching all values. |
| 25 | 25 | // Fired before a `fetchAll` operation. |
| 26 | 26 | // beforeFetchAll: async (model, columns, options) => {}, |
| ... | ... | @@ -31,7 +31,12 @@ module.exports = { |
| 31 | 31 | |
| 32 | 32 | // Before creating a value. |
| 33 | 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 | 41 | // After creating a value. |
| 37 | 42 | // Fired after an `insert` query. | ... | ... |
back-end/h5-api/api/work/models/Work.settings.json
| ... | ... | @@ -16,10 +16,12 @@ |
| 16 | 16 | "attributes": { |
| 17 | 17 | "title": { |
| 18 | 18 | "required": true, |
| 19 | - "type": "string" | |
| 19 | + "type": "string", | |
| 20 | + "default": "default title" | |
| 20 | 21 | }, |
| 21 | 22 | "description": { |
| 22 | - "type": "text" | |
| 23 | + "type": "text", | |
| 24 | + "default": "default desc" | |
| 23 | 25 | }, |
| 24 | 26 | "cover_image_url": { |
| 25 | 27 | "type": "string" | ... | ... |