Updated seeder with subscriptions rules
This commit is contained in:
parent
5c7522e7bc
commit
70815657e8
@ -1,7 +1,7 @@
|
|||||||
import authHandler from "@App/middlewares/AuthHandler";
|
import authHandler from "@App/middlewares/AuthHandler";
|
||||||
// import roleHandler from "@App/middlewares/RolesHandler";
|
// import roleHandler from "@App/middlewares/RolesHandler";
|
||||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||||
import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
import { Controller, Get, Post} from "@ControllerPattern/index";
|
||||||
import StripeService from "@Services/common/StripeService/StripeService";
|
import StripeService from "@Services/common/StripeService/StripeService";
|
||||||
import { validateOrReject } from "class-validator";
|
import { validateOrReject } from "class-validator";
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
@ -41,31 +41,31 @@ export default class StripeController extends ApiController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put("/api/v1/admin/stripe/:uid")
|
// @Put("/api/v1/admin/stripe/:uid")
|
||||||
protected async createStripeSubscriptionUpdateCheckout(req: Request, response: Response) {
|
// protected async createStripeSubscriptionUpdateCheckout(req: Request, response: Response) {
|
||||||
try {
|
// try {
|
||||||
const uid = req.params["uid"];
|
// const uid = req.params["uid"];
|
||||||
if (!uid) {
|
// if (!uid) {
|
||||||
this.httpBadRequest(response, "No uid provided");
|
// this.httpBadRequest(response, "No uid provided");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
const officeId: string = req.body.user.office_Id;
|
// const officeId: string = req.body.user.office_Id;
|
||||||
//add office id to request body
|
// //add office id to request body
|
||||||
req.body.office = { uid: officeId };
|
// req.body.office = { uid: officeId };
|
||||||
|
|
||||||
//init Subscription resource with request body values
|
// //init Subscription resource with request body values
|
||||||
const subscriptionEntity = Subscription.hydrate<Subscription>(req.body, { strategy: "excludeAll" });
|
// const subscriptionEntity = Subscription.hydrate<Subscription>(req.body, { strategy: "excludeAll" });
|
||||||
|
|
||||||
await validateOrReject(subscriptionEntity, { groups: ["updateSubscription"], forbidUnknownValues: false });
|
// await validateOrReject(subscriptionEntity, { groups: ["updateSubscription"], forbidUnknownValues: false });
|
||||||
|
|
||||||
const stripeSession = await this.stripeService.createCheckoutSessionUpdate(uid, subscriptionEntity);
|
// const stripeSession = await this.stripeService.createCheckoutSessionUpdate(uid, subscriptionEntity);
|
||||||
|
|
||||||
this.httpCreated(response, stripeSession);
|
// this.httpCreated(response, stripeSession);
|
||||||
} catch (error) {
|
// } catch (error) {
|
||||||
this.httpInternalError(response, error);
|
// this.httpInternalError(response, error);
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Get("/api/v1/admin/stripe/:uid", [authHandler])
|
@Get("/api/v1/admin/stripe/:uid", [authHandler])
|
||||||
protected async getClientPortalSession(req: Request, response: Response) {
|
protected async getClientPortalSession(req: Request, response: Response) {
|
||||||
|
@ -8,7 +8,6 @@ import { Service } from "typedi";
|
|||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "@prisma/client";
|
||||||
import SubscriptionsService from "@Services/admin/SubscriptionsService/SubscriptionsService.ts";
|
import SubscriptionsService from "@Services/admin/SubscriptionsService/SubscriptionsService.ts";
|
||||||
import { Subscription } from "le-coffre-resources/dist/Admin";
|
import { Subscription } from "le-coffre-resources/dist/Admin";
|
||||||
import { validateOrReject } from "class-validator";
|
|
||||||
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
||||||
import roleHandler from "@App/middlewares/RolesHandler";
|
import roleHandler from "@App/middlewares/RolesHandler";
|
||||||
import authHandler from "@App/middlewares/AuthHandler";
|
import authHandler from "@App/middlewares/AuthHandler";
|
||||||
@ -81,29 +80,29 @@ export default class SubscriptionsController extends ApiController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* @description Create a new documentType
|
// * @description Create a new documentType
|
||||||
*/
|
// */
|
||||||
@Post("/api/v1/admin/subscriptions", [authHandler, roleHandler])
|
// @Post("/api/v1/admin/subscriptions", [authHandler, roleHandler])
|
||||||
protected async post(req: Request, response: Response) {
|
// protected async post(req: Request, response: Response) {
|
||||||
try {
|
// try {
|
||||||
//init Subscription resource with request body values
|
// //init Subscription resource with request body values
|
||||||
const subscriptionEntity = Subscription.hydrate<Subscription>(req.body);
|
// const subscriptionEntity = Subscription.hydrate<Subscription>(req.body);
|
||||||
//validate subscription
|
// //validate subscription
|
||||||
await validateOrReject(subscriptionEntity, { groups: ["createSubscription"], forbidUnknownValues: false });
|
// await validateOrReject(subscriptionEntity, { groups: ["createSubscription"], forbidUnknownValues: false });
|
||||||
//call service to get prisma entity
|
// //call service to get prisma entity
|
||||||
const subscriptionEntityCreated = await this.subscriptionsService.create(subscriptionEntity);
|
// const subscriptionEntityCreated = await this.subscriptionsService.create(subscriptionEntity);
|
||||||
//Hydrate ressource with prisma entity
|
// //Hydrate ressource with prisma entity
|
||||||
const subscription = Subscription.hydrate<Subscription>(subscriptionEntityCreated, {
|
// const subscription = Subscription.hydrate<Subscription>(subscriptionEntityCreated, {
|
||||||
strategy: "excludeAll",
|
// strategy: "excludeAll",
|
||||||
});
|
// });
|
||||||
//success
|
// //success
|
||||||
this.httpCreated(response, subscription);
|
// this.httpCreated(response, subscription);
|
||||||
} catch (error) {
|
// } catch (error) {
|
||||||
this.httpInternalError(response, error);
|
// this.httpInternalError(response, error);
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Update a subscription
|
* @description Update a subscription
|
||||||
|
@ -795,6 +795,41 @@ export default async function main() {
|
|||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
namespace: "notary",
|
namespace: "notary",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "GET subscriptions",
|
||||||
|
label: "Récupérer les abonnements",
|
||||||
|
created_at: new Date(),
|
||||||
|
updated_at: new Date(),
|
||||||
|
namespace: "notary",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "POST subscriptions",
|
||||||
|
label: "Inviter un collaborateur à l'abonnement",
|
||||||
|
created_at: new Date(),
|
||||||
|
updated_at: new Date(),
|
||||||
|
namespace: "notary",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "PUT subscriptions",
|
||||||
|
label: "Modifier l'abonnement",
|
||||||
|
created_at: new Date(),
|
||||||
|
updated_at: new Date(),
|
||||||
|
namespace: "notary",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "GET stripe",
|
||||||
|
label: "Gérer l'abonnement de l'office",
|
||||||
|
created_at: new Date(),
|
||||||
|
updated_at: new Date(),
|
||||||
|
namespace: "notary",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "POST stripe",
|
||||||
|
label: "Payer un abonnement",
|
||||||
|
created_at: new Date(),
|
||||||
|
updated_at: new Date(),
|
||||||
|
namespace: "notary",
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const collaboratorRules = rules.filter((rule) => rule.namespace === "collaborator");
|
const collaboratorRules = rules.filter((rule) => rule.namespace === "collaborator");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user