Merge branch 'staging' into preprod

This commit is contained in:
Vins 2024-04-24 09:50:56 +02:00
commit f073b761d1
6 changed files with 15 additions and 20 deletions

View File

@ -124,9 +124,7 @@ export default class OfficeRolesController extends ApiController {
return; return;
} }
if (req.body.rules) { if (req.body.rules) {
console.log(req.body.rules);
const allRules = await this.rulesService.get({ const allRules = await this.rulesService.get({
where: { where: {
namespace: "global", namespace: "global",

View File

@ -35,11 +35,11 @@ export default class UserController extends ApiController {
@Post("/api/v1/idnot/user/:code") @Post("/api/v1/idnot/user/:code")
protected async getUserInfosFromIdnot(req: Request, response: Response) { protected async getUserInfosFromIdnot(req: Request, response: Response) {
try { try {
const code = req.params["code"]; const code = req.params["code"];
if (!code) throw new Error("code is required"); if (!code) throw new Error("code is required");
const idNotToken = await this.idNotService.getIdNotToken(code); const idNotToken = await this.idNotService.getIdNotToken(code);
if (!idNotToken) { if (!idNotToken) {
this.httpValidationError(response, "IdNot token undefined"); this.httpValidationError(response, "IdNot token undefined");
@ -73,7 +73,7 @@ export default class UserController extends ApiController {
} }
let isSubscribed = false; let isSubscribed = false;
const subscriptions = await this.subscriptionsService.get({ where: { office_uid: userHydrated.office_membership?.uid } }); const subscriptions = await this.subscriptionsService.get({ where: { office_uid: userHydrated.office_membership?.uid } });
if (!subscriptions || subscriptions.length === 0 || subscriptions[0]?.status === ESubscriptionStatus.INACTIVE) { if (!subscriptions || subscriptions.length === 0 || subscriptions[0]?.status === ESubscriptionStatus.INACTIVE) {
isSubscribed = false; isSubscribed = false;
@ -116,19 +116,21 @@ export default class UserController extends ApiController {
await this.idNotService.updateOffice(user.office_uid); await this.idNotService.updateOffice(user.office_uid);
const payload = await this.authService.getUserJwtPayload(user.idNot); const payload = await this.authService.getUserJwtPayload(user.idNot);
if(!payload) return; if(!payload) return;
if(!isSubscribed && userHydrated.role?.name === "admin" || userHydrated.role?.name === "super-admin"){ if(!isSubscribed && userHydrated.role?.name === "admin" || userHydrated.role?.name === "super-admin"){
const manageSubscriptionRulesEntity = await this.rulesGroupsService.get({ where: { name: "Gestion de l'abonnement" }, include: { rules: true } }); const manageSubscriptionRulesEntity = await this.rulesGroupsService.get({ where: { uid: "94343601-04c8-44ef-afb9-3047597528a9" }, include: { rules: true } });
const manageSubscriptionRules = RulesGroup.hydrateArray<RulesGroup>(manageSubscriptionRulesEntity, { strategy: "excludeAll" }); console.log(manageSubscriptionRulesEntity);
const manageSubscriptionRules = RulesGroup.hydrateArray<RulesGroup>(manageSubscriptionRulesEntity, { strategy: "excludeAll" });
if(!manageSubscriptionRules[0]) return; if(!manageSubscriptionRules[0]) return;
payload.rules = manageSubscriptionRules[0].rules!.map((rule) => rule.name) || []; payload.rules = manageSubscriptionRules[0].rules!.map((rule) => rule.name) || [];
isSubscribed = true; isSubscribed = true;
} }
if (!isSubscribed) { if (!isSubscribed) {
this.httpUnauthorized(response, "User not subscribed"); this.httpUnauthorized(response, "User not subscribed");
return; return;

View File

@ -157,12 +157,6 @@ export class BackendVariables {
@IsNotEmpty() @IsNotEmpty()
public readonly STRIPE_UNLIMITED_ANNUAL_SUBSCRIPTION_PRICE_ID!: string; public readonly STRIPE_UNLIMITED_ANNUAL_SUBSCRIPTION_PRICE_ID!: string;
@IsNotEmpty()
public readonly STRIPE_PAYMENT_SUCCESS_URL!: string;
@IsNotEmpty()
public readonly STRIPE_PAYMENT_CANCEL_URL!: string;
@IsNotEmpty() @IsNotEmpty()
public readonly IDNOT_PROD_BASE_URL!: string; public readonly IDNOT_PROD_BASE_URL!: string;
@ -219,8 +213,6 @@ export class BackendVariables {
this.STRIPE_STANDARD_ANNUAL_SUBSCRIPTION_PRICE_ID = process.env["STRIPE_STANDARD_ANNUAL_SUBSCRIPTION_PRICE_ID"]!; this.STRIPE_STANDARD_ANNUAL_SUBSCRIPTION_PRICE_ID = process.env["STRIPE_STANDARD_ANNUAL_SUBSCRIPTION_PRICE_ID"]!;
this.STRIPE_UNLIMITED_SUBSCRIPTION_PRICE_ID = process.env["STRIPE_UNLIMITED_SUBSCRIPTION_PRICE_ID"]!; this.STRIPE_UNLIMITED_SUBSCRIPTION_PRICE_ID = process.env["STRIPE_UNLIMITED_SUBSCRIPTION_PRICE_ID"]!;
this.STRIPE_UNLIMITED_ANNUAL_SUBSCRIPTION_PRICE_ID = process.env["STRIPE_UNLIMITED_ANNUAL_SUBSCRIPTION_PRICE_ID"]!; this.STRIPE_UNLIMITED_ANNUAL_SUBSCRIPTION_PRICE_ID = process.env["STRIPE_UNLIMITED_ANNUAL_SUBSCRIPTION_PRICE_ID"]!;
this.STRIPE_PAYMENT_SUCCESS_URL = process.env["STRIPE_PAYMENT_SUCCESS_URL"]!;
this.STRIPE_PAYMENT_CANCEL_URL = process.env["STRIPE_PAYMENT_CANCEL_URL"]!;
this.IDNOT_PROD_BASE_URL = process.env["IDNOT_PROD_BASE_URL"]!; this.IDNOT_PROD_BASE_URL = process.env["IDNOT_PROD_BASE_URL"]!;
} }
public async validate(groups?: string[]) { public async validate(groups?: string[]) {

View File

@ -874,6 +874,7 @@ export default async function main() {
}, },
{ {
name: "Gestion de l'abonnement", name: "Gestion de l'abonnement",
uid: "94343601-04c8-44ef-afb9-3047597528a9",
created_at: new Date(), created_at: new Date(),
updated_at: new Date(), updated_at: new Date(),
rules : [ rules : [
@ -1973,6 +1974,7 @@ export default async function main() {
for (const ruleGroup of rulesGroups) { for (const ruleGroup of rulesGroups) {
await prisma.rulesGroups.create({ await prisma.rulesGroups.create({
data: { data: {
uid: ruleGroup.uid,
name: ruleGroup.name, name: ruleGroup.name,
rules: { rules: {
connect: ruleGroup.rules?.map((rule) => ({ connect: ruleGroup.rules?.map((rule) => ({

View File

@ -14,7 +14,7 @@ const storage = multer.memoryStorage();
(async () => { (async () => {
try { try {
const variables = await Container.get(BackendVariables).validate(); const variables = await Container.get(BackendVariables).validate();
const port = variables.APP_PORT; const port = variables.APP_PORT;
const rootUrl = variables.APP_ROOT_URL; const rootUrl = variables.APP_ROOT_URL;
const label = variables.APP_LABEL ?? "Unknown Service"; const label = variables.APP_LABEL ?? "Unknown Service";

View File

@ -122,13 +122,14 @@ export default class IdNotService extends BaseService {
grant_type: "authorization_code", grant_type: "authorization_code",
}); });
const token = await fetch(this.variables.IDNOT_BASE_URL + this.variables.IDNOT_CONNEXION_URL + "?" + query, { method: "POST" }); const token = await fetch(this.variables.IDNOT_BASE_URL + this.variables.IDNOT_CONNEXION_URL + "?" + query, { method: "POST" });
if(token.status !== 200) console.error(await token.text()); if(token.status !== 200) console.error(await token.text());
const decodedToken = (await token.json()) as IIdNotToken; const decodedToken = (await token.json()) as IIdNotToken;
const decodedIdToken = jwt.decode(decodedToken.id_token) as IdNotJwtPayload; const decodedIdToken = jwt.decode(decodedToken.id_token) as IdNotJwtPayload;
return decodedIdToken; return decodedIdToken;