all repos — caroster @ 5ecddb30cd1351970186d1d7939cad57554ce781

[Octree] Group carpool to your event https://caroster.io

backend/api/car/controllers/car.js (view raw)

 1'use strict';
 2
 3module.exports = {
 4  async create(ctx) {
 5    const car = await strapi.services.car.create(ctx.request.body);
 6    if (car) return strapi.services.car.sanitize(car);
 7    else return ctx.badRequest('No car found');
 8  },
 9
10  async update(ctx) {
11    const {id} = ctx.params;
12
13    try {
14      const car = await strapi.services.car.update({id}, ctx.request.body);
15      return strapi.services.car.sanitize(car);
16    } catch (error) {
17      strapi.log.error(error);
18      return ctx.badRequest('No car found');
19    }
20  },
21
22  async delete(ctx) {
23    const {id} = ctx.params;
24
25    try {
26      const car = await strapi.services.car.delete({id});
27      return strapi.services.car.sanitize(car);
28    } catch (error) {
29      strapi.log.error(error);
30      return ctx.badRequest('No car found');
31    }
32  },
33};