mirror of
				https://github.com/strapi/strapi.git
				synced 2025-10-30 17:37:26 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			115 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Plaintext
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			115 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Plaintext
		
	
	
		
			Executable File
		
	
	
	
	
| 'use strict';
 | |
| 
 | |
| /**
 | |
|  * <%= filename %> controller
 | |
|  *
 | |
|  * @description: A set of functions called "actions" for managing `<%= globalID %>`.
 | |
|  */
 | |
| 
 | |
| module.exports = {
 | |
| 
 | |
|   /**
 | |
|    * Retrieve <%= id %> records.
 | |
|    *
 | |
|    * @return {Object|Array}
 | |
|    */
 | |
| 
 | |
|   find: async (ctx) => {
 | |
|     const data = await strapi.services.<%= id %>.fetchAll(ctx.query);
 | |
| 
 | |
|     // Send 200 `ok`
 | |
|     ctx.send(data);
 | |
|   },
 | |
| 
 | |
|   /**
 | |
|    * Retrieve a <%= id %> record.
 | |
|    *
 | |
|    * @return {Object}
 | |
|    */
 | |
| 
 | |
|   findOne: async (ctx) => {
 | |
|     const data = await strapi.services.<%= id %>.fetch(ctx.params);
 | |
| 
 | |
|     // Send 200 `ok`
 | |
|     ctx.send(data);
 | |
|   },
 | |
| 
 | |
|   /**
 | |
|    * Create a/an <%= id %> record.
 | |
|    *
 | |
|    * @return {Object}
 | |
|    */
 | |
| 
 | |
|   create: async (ctx) => {
 | |
|     const data = await strapi.services.<%= id %>.add(ctx.request.body);
 | |
| 
 | |
|     // Send 201 `created`
 | |
|     ctx.created(data);
 | |
|   },
 | |
| 
 | |
|   /**
 | |
|    * Update a/an <%= id %> record.
 | |
|    *
 | |
|    * @return {Object}
 | |
|    */
 | |
| 
 | |
|   update: async (ctx, next) => {
 | |
|     const data = await strapi.services.<%= id %>.edit(ctx.params, ctx.request.body) ;
 | |
| 
 | |
|     // Send 200 `ok`
 | |
|     ctx.send(data);
 | |
|   },
 | |
| 
 | |
|   /**
 | |
|    * Destroy a/an <%= id %> record.
 | |
|    *
 | |
|    * @return {Object}
 | |
|    */
 | |
| 
 | |
|   destroy: async (ctx, next) => {
 | |
|     const data = await strapi.services.<%= id %>.remove(ctx.params);
 | |
| 
 | |
|     // Send 200 `ok`
 | |
|     ctx.send(data);
 | |
|   },
 | |
| 
 | |
|   /**
 | |
|    * Add relation to a/an <%= id %> record.
 | |
|    *
 | |
|    * @return {Object}
 | |
|    */
 | |
| 
 | |
|   createRelation: async (ctx, next) => {
 | |
|     const data = await strapi.services.<%= id %>.addRelation(ctx.params, ctx.request.body);
 | |
| 
 | |
|     // Send 200 `ok`
 | |
|     ctx.send(data);
 | |
|   },
 | |
| 
 | |
|   /**
 | |
|    * Update relation to a/an <%= id %> record.
 | |
|    *
 | |
|    * @return {Object}
 | |
|    */
 | |
| 
 | |
|   updateRelation: async (ctx, next) => {
 | |
|     const data = await strapi.services.<%= id %>.editRelation(ctx.params, ctx.request.body);
 | |
| 
 | |
|     // Send 200 `ok`
 | |
|     ctx.send(data);
 | |
|   },
 | |
| 
 | |
|   /**
 | |
|    * Destroy relation to a/an <%= id %> record.
 | |
|    *
 | |
|    * @return {Object}
 | |
|    */
 | |
| 
 | |
|   destroyRelation: async (ctx, next) => {
 | |
|     const data = await strapi.services.<%= id %>.removeRelation(ctx.params, ctx.request.body);
 | |
| 
 | |
|     // Send 200 `ok`
 | |
|     ctx.send(data);
 | |
|   }
 | |
| };
 | 
