Replace restaurant in webhook doc

This commit is contained in:
Jim LAURIE 2019-09-24 17:30:16 +02:00
parent 22615a1db9
commit 2580b471d4

View File

@ -8,18 +8,18 @@ But what we like at Strapi is to help developers. So even if the feature is not
As you may know, every Content Type (aka models) has lifecycle callbacks: functions which are triggered every time an entry is fetched, inserted, updated or deleted. Here is the list: As you may know, every Content Type (aka models) has lifecycle callbacks: functions which are triggered every time an entry is fetched, inserted, updated or deleted. Here is the list:
- Callbacks on `save` (both triggered on entry creation and update): `beforeSave`, `afterSave`. - Callbacks on `save` (both triggered on entry creation and update): `beforeSave`, `afterSave`.
- Callbacks on `fetch`: `beforeFetch`, `afterFetch`. - Callbacks on `fetch`: `beforeFetch`, `afterFetch`.
- Callbacks on `fetchAll`: `beforeFetchAll`, `afterFetchAll`. - Callbacks on `fetchAll`: `beforeFetchAll`, `afterFetchAll`.
- Callbacks on `create`: `beforeCreate`, `afterCreate`. - Callbacks on `create`: `beforeCreate`, `afterCreate`.
- Callbacks on `update`: `beforeUpdate`, `afterUpdate`. - Callbacks on `update`: `beforeUpdate`, `afterUpdate`.
- Callbacks on `destroy`: `beforeDestroy`, `afterDestroy`. - Callbacks on `destroy`: `beforeDestroy`, `afterDestroy`.
All of these functions are available in a file located at `api/yourContentType/models/YourContentType.js`. All of these functions are available in a file located at `api/restaurant/models/Restaurant.js`.
If your goal is to rebuild a static website, the only useful callbacks are `afterCreate`, `afterUpdate` and `afterDestroy`. So, uncomment them, add logs and try to create, update and delete entries from the admin panel. If your goal is to rebuild a static website, the only useful callbacks are `afterCreate`, `afterUpdate` and `afterDestroy`. So, uncomment them, add logs and try to create, update and delete entries from the admin panel.
**Path —** `api/yourContentType/models/YourContentType.js`. **Path —** `api/restaurant/models/Restaurant.js`.
```js ```js
'use strict'; 'use strict';
@ -28,18 +28,18 @@ If your goal is to rebuild a static website, the only useful callbacks are `afte
* Lifecycle callbacks for the `Post` model. * Lifecycle callbacks for the `Post` model.
*/ */
module.exports = { module.exports = {
afterCreate: async (entry) => { afterCreate: async entry => {
console.log('afterCreate'); console.log('afterCreate');
}, },
afterUpdate: async (entry) => { afterUpdate: async entry => {
console.log('afterUpdate'); console.log('afterUpdate');
}, },
afterDestroy: async (entry) => { afterDestroy: async entry => {
console.log('afterDestroy'); console.log('afterDestroy');
} },
}; };
``` ```
@ -69,9 +69,9 @@ Now it is time to make the HTTP call. In this example we will use `axios`. Let's
npm i axios --save npm i axios --save
``` ```
Edit `api/yourContentType/models/YourContentType.js`: Edit `api/restaurant/models/Restaurant.js`:
**Path —** `api/yourContentType/models/YourContentType.js`. **Path —** `api/restaurant/models/Restaurant.js`.
```js ```js
'use strict'; 'use strict';
@ -82,30 +82,30 @@ const axios = require('axios');
* Lifecycle callbacks for the `Post` model. * Lifecycle callbacks for the `Post` model.
*/ */
module.exports = { module.exports = {
afterCreate: async (entry) => { afterCreate: async entry => {
axios.post(strapi.config.currentEnvironment.staticWebsiteBuildURL, entry) axios
.post(strapi.config.currentEnvironment.staticWebsiteBuildURL, entry)
.catch(() => { .catch(() => {
// Ignore // Ignore
} });
);
}, },
afterUpdate: async (entry) => { afterUpdate: async entry => {
axios.post(strapi.config.currentEnvironment.staticWebsiteBuildURL, entry) axios
.post(strapi.config.currentEnvironment.staticWebsiteBuildURL, entry)
.catch(() => { .catch(() => {
// Ignore // Ignore
} });
);
}, },
afterDestroy: async (entry) => { afterDestroy: async entry => {
axios.post(strapi.config.currentEnvironment.staticWebsiteBuildURL, entry) axios
.post(strapi.config.currentEnvironment.staticWebsiteBuildURL, entry)
.catch(() => { .catch(() => {
// Ignore // Ignore
} });
); },
}
}; };
``` ```
@ -115,8 +115,8 @@ Until September 2018, `remove` lifecycle callback [was not supported by Mongoose
So, to trigger an url on delete, please add `request.post(strapi.config.currentEnvironment.staticWebsiteBuildURL, entry);` in: So, to trigger an url on delete, please add `request.post(strapi.config.currentEnvironment.staticWebsiteBuildURL, entry);` in:
- `remove` action of `api/yourContentType/services/YourContentType.js` (triggered by your public API). - `remove` action of `api/restaurant/services/Restaurant.js` (triggered by your public API).
- `delete` action of `plugins/content-manager/services/ContentManager.js` (triggered by the Content Manager). - `delete` action of `plugins/content-manager/services/ContentManager.js` (triggered by the Content Manager).
::: note ::: note
Do not forget to require `axios` at the top of these files. Do not forget to require `axios` at the top of these files.