Open dguglielmi-git opened 1 year ago
Cart Endpoint route:
"routes": [ { "method": "GET", "path": "/carts", "handler": "cart.find", "config": { "policies": [] } }, { "method": "GET", "path": "/carts/count", "handler": "cart.count", "config": { "policies": [] } }, { "method": "GET", "path": "/carts/:id", "handler": "cart.findOne", "config": { "policies": [] } }, { "method": "POST", "path": "/carts", "handler": "cart.create", "config": { "policies": [] } }, { "method": "PUT", "path": "/carts/:id", "handler": "cart.update", "config": { "policies": [] } }, { "method": "DELETE", "path": "/carts", "handler": "custom.deleteByUsername", "config": { "policies": [] } }, { "method": "DELETE", "path": "/carts/:id", "handler": "cart.delete", "config": { "policies": [] } } ]
Code of custom Controller:
async deleteByUsername(ctx) { console.log(jwtDecode(ctx.request.header.authorization)); const { id } = await jwtDecode(ctx.request.header.authorization); strapi.query('cart').delete({ users_permissions_user: id }); }
Cart Model:
"collectionName": "carts", "info": { "name": "cart" }, "options": { "increments": true, "timestamps": true, "draftAndPublish": true }, "pluginOptions": {}, "attributes": { "users_permissions_user": { "plugin": "users-permissions", "model": "user" }, "producto": { "model": "producto" }, "quantity": { "type": "integer" } }
Cart Endpoint route:
Code of custom Controller:
Cart Model: