@dbbs/strapi-stripe-payment
Version:
Strapi integration plugin for Stripe payment system
52 lines (51 loc) • 2.46 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const http_errors_1 = __importDefault(require("http-errors"));
const strapi_1 = require("@strapi/strapi");
const validationSchemas_1 = require("../validationSchemas");
const helpers_1 = require("../helpers");
exports.default = strapi_1.factories.createCoreController('plugin::stripe-payment.product', ({ strapi }) => ({
async create(ctx) {
const { name } = ctx.request.body;
const validatedParams = await (0, helpers_1.validateWithYupSchema)(validationSchemas_1.createProductSchema, {
name
});
const product = await strapi.plugin('stripe-payment').service('product').create(validatedParams);
ctx.send(product);
},
async getProductById(ctx) {
const { id } = ctx.params;
const validatedParams = await (0, helpers_1.validateWithYupSchema)(validationSchemas_1.getProductByIdSchema, { id });
const product = await strapi.plugin('stripe-payment').service('product').getProductById(validatedParams);
if (!product) {
throw new http_errors_1.default.NotFound(`Product with ID ${id} not found`);
}
ctx.send(product);
},
async getProducts(ctx) {
const products = await strapi.plugin('stripe-payment').service('product').getProducts();
ctx.send(products);
},
async update(ctx) {
const { id } = ctx.params;
const { name } = ctx.request.body;
const validatedParams = await (0, helpers_1.validateWithYupSchema)(validationSchemas_1.updateProductSchema, { id, name });
const product = await strapi.plugin('stripe-payment').service('product').update(validatedParams);
if (!product) {
throw new http_errors_1.default.NotFound(`Product with ID ${id} not found`);
}
ctx.send(product);
},
async delete(ctx) {
const { id } = ctx.params;
const validatedParams = await (0, helpers_1.validateWithYupSchema)(validationSchemas_1.deleteProductSchema, { id });
const result = await strapi.plugin('stripe-payment').service('product').delete(validatedParams);
if (!result) {
throw new http_errors_1.default.NotFound(`Product with ID ${id} not found`);
}
ctx.send(result);
}
}));