Merge branch 'staging' into preprod
This commit is contained in:
commit
56dcba7c30
@ -169,7 +169,7 @@ export default class CustomersController extends ApiController {
|
||||
//success
|
||||
this.httpSuccess(response, customer);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
this.httpValidationError(response, error);
|
||||
return;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ export default class AuthController extends ApiController {
|
||||
totpCodeUid: res.totpCode.uid,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
this.httpInternalError(response);
|
||||
}
|
||||
}
|
||||
@ -64,7 +64,7 @@ export default class AuthController extends ApiController {
|
||||
this.httpTooEarlyRequest(response, error.message);
|
||||
return;
|
||||
}
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
this.httpInternalError(response);
|
||||
}
|
||||
}
|
||||
@ -112,7 +112,7 @@ export default class AuthController extends ApiController {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
@ -168,7 +168,7 @@ export default class AuthController extends ApiController {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
@ -203,7 +203,7 @@ export default class AuthController extends ApiController {
|
||||
this.httpUnauthorized(response, error.message);
|
||||
return;
|
||||
}
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
this.httpInternalError(response);
|
||||
}
|
||||
}
|
||||
@ -237,7 +237,7 @@ export default class AuthController extends ApiController {
|
||||
this.httpUnauthorized(response, error.message);
|
||||
return;
|
||||
}
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
this.httpInternalError(response);
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,6 @@ export default class DocumentsController extends ApiController {
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if (query.folder) delete query.folder;
|
||||
|
||||
}
|
||||
|
||||
const documentEntity = await this.documentsService.getByUid(uid, query);
|
||||
@ -90,7 +89,7 @@ export default class DocumentsController extends ApiController {
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ export default class CustomerController extends ApiController {
|
||||
const enrollment = await this.id360Service.createFranceConnectEnrollment();
|
||||
this.httpSuccess(response, { enrollment });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
@ -77,7 +77,7 @@ export default class CustomerController extends ApiController {
|
||||
const refreshToken = this.authService.generateRefreshToken(payload);
|
||||
this.httpSuccess(response, { accessToken, refreshToken });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
@ -89,7 +89,7 @@ export default class CustomerController extends ApiController {
|
||||
const token = await this.id360Service.getId360Token();
|
||||
this.httpSuccess(response, { token });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
@ -109,7 +109,7 @@ export default class CustomerController extends ApiController {
|
||||
let accessToken;
|
||||
this.authService.verifyRefreshToken(token, (err, userPayload) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
console.error(err);
|
||||
this.httpUnauthorized(response);
|
||||
return;
|
||||
}
|
||||
@ -123,7 +123,7 @@ export default class CustomerController extends ApiController {
|
||||
//success
|
||||
this.httpSuccess(response, { accessToken });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
|
@ -18,11 +18,10 @@ export default class DocumentController extends ApiController {
|
||||
*/
|
||||
@Post("/api/v1/id360/enrollment-callback/")
|
||||
protected async getDocumentVerificationFromId360(req: Request, response: Response) {
|
||||
|
||||
try {
|
||||
this.httpSuccess(response);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
@ -30,11 +29,10 @@ export default class DocumentController extends ApiController {
|
||||
|
||||
@Post("/api/v1/id360/customer-callback/")
|
||||
protected async getCustomerVerificationFromId360(req: Request, response: Response) {
|
||||
|
||||
try {
|
||||
this.httpSuccess(response);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
@ -52,7 +50,7 @@ export default class DocumentController extends ApiController {
|
||||
//success
|
||||
this.httpSuccess(response);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
|
@ -26,12 +26,9 @@ export default class UserController extends ApiController {
|
||||
|
||||
this.httpSuccess(response, officeMemberships);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -8,9 +8,6 @@ import IdNotService from "@Services/common/IdNotService/IdNotService";
|
||||
import User, { RulesGroup } from "le-coffre-resources/dist/Admin";
|
||||
import UsersService from "@Services/super-admin/UsersService/UsersService";
|
||||
import SubscriptionsService from "@Services/admin/SubscriptionsService/SubscriptionsService.ts";
|
||||
import { ESubscriptionStatus } from "@prisma/client";
|
||||
import SeatsService from "@Services/admin/SeatsService/SeatsService";
|
||||
import { EType } from "le-coffre-resources/dist/Admin/Subscription";
|
||||
import RulesGroupsService from "@Services/admin/RulesGroupsService/RulesGroupsService";
|
||||
|
||||
@Controller()
|
||||
@ -21,7 +18,6 @@ export default class UserController extends ApiController {
|
||||
private idNotService: IdNotService,
|
||||
private userService: UsersService,
|
||||
private subscriptionsService: SubscriptionsService,
|
||||
private seatsService: SeatsService,
|
||||
private rulesGroupsService: RulesGroupsService,
|
||||
) {
|
||||
super();
|
||||
@ -58,7 +54,6 @@ export default class UserController extends ApiController {
|
||||
//Whitelist feature
|
||||
//Get user with contact
|
||||
const prismaUser = await this.userService.getByUid(user.uid, { contact: true, role: true, office_membership: true });
|
||||
console.log(prismaUser);
|
||||
|
||||
if (!prismaUser) {
|
||||
this.httpNotFoundRequest(response, "user not found");
|
||||
@ -67,46 +62,12 @@ export default class UserController extends ApiController {
|
||||
|
||||
//Hydrate user to be able to use his contact
|
||||
const userHydrated = User.hydrate<User>(prismaUser, { strategy: "excludeAll" });
|
||||
console.log(userHydrated);
|
||||
|
||||
if (!userHydrated.contact?.email || userHydrated.contact?.email === "") {
|
||||
this.httpUnauthorized(response, "Email not found");
|
||||
return;
|
||||
}
|
||||
let isSubscribed = false;
|
||||
|
||||
const subscriptions = await this.subscriptionsService.get({ where: { office_uid: userHydrated.office_membership?.uid } });
|
||||
console.log(subscriptions);
|
||||
|
||||
if (!subscriptions || subscriptions.length === 0 || subscriptions[0]?.status === ESubscriptionStatus.INACTIVE) {
|
||||
console.log("No subscription found");
|
||||
isSubscribed = false;
|
||||
}
|
||||
else if (subscriptions[0]?.type === EType.Unlimited) {
|
||||
console.log("Unlimited subscription found");
|
||||
isSubscribed = true;
|
||||
} else {
|
||||
console.log("Standard subscription found");
|
||||
const hasSeat = await this.subscriptionsService.get({
|
||||
where: { status: ESubscriptionStatus.ACTIVE, seats: { some: { user_uid: userHydrated.uid } } },
|
||||
});
|
||||
|
||||
if (hasSeat && hasSeat.length > 0) {
|
||||
isSubscribed = true;
|
||||
} else {
|
||||
const nbMaxSeats = subscriptions[0]!.nb_seats;
|
||||
|
||||
const nbCurrentSeats = await this.seatsService.get({ where: { subscription_uid: subscriptions[0]!.uid } });
|
||||
|
||||
//if nbMaxSeats < nbCurrentSeats, create a new seat for the user
|
||||
if (nbMaxSeats > nbCurrentSeats.length) {
|
||||
const seatAdded = await this.seatsService.create(user.uid, subscriptions[0]!.uid);
|
||||
if (seatAdded) {
|
||||
isSubscribed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let isSubscribed = await this.subscriptionsService.isUserSubscribed(user.uid, userHydrated.office_membership?.uid!);
|
||||
|
||||
//Check if user is whitelisted
|
||||
// const isWhitelisted = await this.whitelistService.getByEmail(userHydrated.contact!.email);
|
||||
@ -123,24 +84,17 @@ export default class UserController extends ApiController {
|
||||
await this.idNotService.updateOffice(user.office_uid);
|
||||
|
||||
const payload = await this.authService.getUserJwtPayload(user.idNot);
|
||||
console.log(payload);
|
||||
if (!payload) return;
|
||||
|
||||
console.log(isSubscribed, userHydrated.role?.name);
|
||||
if(!isSubscribed && userHydrated.role?.name === "admin"){
|
||||
const manageSubscriptionRulesEntity = await this.rulesGroupsService.get({ where: { uid: "94343601-04c8-44ef-afb9-3047597528a9" }, include: { rules: true } });
|
||||
if (!isSubscribed && (userHydrated.role?.name === "admin" || userHydrated.role?.name === "super-admin")) {
|
||||
const manageSubscriptionRulesEntity = await this.rulesGroupsService.get({
|
||||
where: { uid: "94343601-04c8-44ef-afb9-3047597528a9" },
|
||||
include: { rules: true },
|
||||
});
|
||||
|
||||
const manageSubscriptionRules = RulesGroup.hydrateArray<RulesGroup>(manageSubscriptionRulesEntity, { strategy: "excludeAll" });
|
||||
if(!manageSubscriptionRules[0]) return;
|
||||
|
||||
payload.rules = manageSubscriptionRules[0].rules!.map((rule) => rule.name) || [];
|
||||
|
||||
isSubscribed = true;
|
||||
}
|
||||
if(!isSubscribed && userHydrated.role?.name === "super-admin"){
|
||||
const manageSubscriptionRulesEntity = await this.rulesGroupsService.get({ where: { uid: "94343601-04c8-44ef-afb9-3047597528a9" }, include: { rules: true } });
|
||||
|
||||
const manageSubscriptionRules = RulesGroup.hydrateArray<RulesGroup>(manageSubscriptionRulesEntity, { strategy: "excludeAll" });
|
||||
const manageSubscriptionRules = RulesGroup.hydrateArray<RulesGroup>(manageSubscriptionRulesEntity, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
if (!manageSubscriptionRules[0]) return;
|
||||
|
||||
payload.rules = manageSubscriptionRules[0].rules!.map((rule) => rule.name) || [];
|
||||
@ -158,7 +112,7 @@ export default class UserController extends ApiController {
|
||||
|
||||
this.httpSuccess(response, { accessToken, refreshToken });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
@ -178,24 +132,43 @@ export default class UserController extends ApiController {
|
||||
let accessToken;
|
||||
this.authService.verifyRefreshToken(token, async (err, userPayload) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
console.error(err);
|
||||
this.httpUnauthorized(response);
|
||||
return;
|
||||
}
|
||||
|
||||
const openId = (userPayload as IUserJwtPayload).openId.userId;
|
||||
if (!openId) return;
|
||||
const newUserPayload = await this.authService.getUserJwtPayload(openId.toString(), PROVIDER_OPENID.idNot);
|
||||
const user = newUserPayload as IUserJwtPayload;
|
||||
delete user.iat;
|
||||
delete user.exp;
|
||||
accessToken = this.authService.generateAccessToken(user);
|
||||
const newUserPayload = (await this.authService.getUserJwtPayload(
|
||||
openId.toString(),
|
||||
PROVIDER_OPENID.idNot,
|
||||
)) as IUserJwtPayload;
|
||||
let isSubscribed = await this.subscriptionsService.isUserSubscribed(newUserPayload.userId, newUserPayload.office_Id);
|
||||
|
||||
if (!isSubscribed && (newUserPayload.role === "admin" || newUserPayload.role === "super-admin")) {
|
||||
const manageSubscriptionRulesEntity = await this.rulesGroupsService.get({
|
||||
where: { uid: "94343601-04c8-44ef-afb9-3047597528a9" },
|
||||
include: { rules: true },
|
||||
});
|
||||
|
||||
const manageSubscriptionRules = RulesGroup.hydrateArray<RulesGroup>(manageSubscriptionRulesEntity, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
if (!manageSubscriptionRules[0]) return;
|
||||
|
||||
newUserPayload.rules = manageSubscriptionRules[0].rules!.map((rule) => rule.name) || [];
|
||||
|
||||
isSubscribed = true;
|
||||
}
|
||||
delete newUserPayload.iat;
|
||||
delete newUserPayload.exp;
|
||||
accessToken = this.authService.generateAccessToken(newUserPayload);
|
||||
this.httpSuccess(response, { accessToken });
|
||||
});
|
||||
|
||||
//success
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ export default class CustomersController extends ApiController {
|
||||
//success
|
||||
this.httpSuccess(response, customer);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
this.httpValidationError(response, error);
|
||||
return;
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ export default class CustomersController extends ApiController {
|
||||
//success
|
||||
this.httpSuccess(response, customer);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
this.httpValidationError(response, error);
|
||||
return;
|
||||
}
|
||||
|
@ -22,9 +22,8 @@ export default function authHandler(req: Request, response: Response, next: Next
|
||||
req.body.user = userPayload;
|
||||
next();
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ export default async function documentHandler(req: Request, response: Response,
|
||||
|
||||
next();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
|
@ -10,7 +10,9 @@ export default async function customerHandler(req: Request, response: Response,
|
||||
|
||||
if (uid) {
|
||||
const customerService = Container.get(CustomersService);
|
||||
const customer = await customerService.get({where:{AND: [{uid: uid}, {office_folders: {some: {office_uid: officeId}}}]}});
|
||||
const customer = await customerService.get({
|
||||
where: { AND: [{ uid: uid }, { office_folders: { some: { office_uid: officeId } } }] },
|
||||
});
|
||||
|
||||
if (!customer[0]) {
|
||||
response.status(HttpCodes.NOT_FOUND).send("Customer not found");
|
||||
@ -19,9 +21,8 @@ export default async function customerHandler(req: Request, response: Response,
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
|
@ -42,9 +42,8 @@ export default async function deedHandler(req: Request, response: Response, next
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ export default async function deedTypeHandler(req: Request, response: Response,
|
||||
|
||||
next();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
|
@ -57,16 +57,15 @@ export default async function documentHandler(req: Request, response: Response,
|
||||
return;
|
||||
}
|
||||
|
||||
if(!folder?.stakeholders.find(stakeholder => stakeholder.uid === req.body.user.userId)) {
|
||||
if (!folder?.stakeholders.find((stakeholder) => stakeholder.uid === req.body.user.userId)) {
|
||||
response.sendStatus(HttpCodes.UNAUTHORIZED).send("Unauthorized with this user");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
|
@ -21,7 +21,9 @@ export default async function documentTypeHandler(req: Request, response: Respon
|
||||
where: { AND: [{ name: { equals: name, mode: "insensitive" } }, { office: { uid: officeId } }] },
|
||||
});
|
||||
if (documentType[0] && (!uid || documentType[0].uid != uid)) {
|
||||
response.status(HttpCodes.VALIDATION_ERROR).send([{ property: "name", constraints: { name: "Nom de document déjà utilisé" } }]);
|
||||
response
|
||||
.status(HttpCodes.VALIDATION_ERROR)
|
||||
.send([{ property: "name", constraints: { name: "Nom de document déjà utilisé" } }]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -42,9 +44,8 @@ export default async function documentTypeHandler(req: Request, response: Respon
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ export default async function fileHandler(req: Request, response: Response, next
|
||||
|
||||
next();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
|
@ -32,7 +32,9 @@ export default async function folderHandler(req: Request, response: Response, ne
|
||||
}
|
||||
|
||||
if (stakeHolders && stakeHolders.length === 0) {
|
||||
response.status(HttpCodes.VALIDATION_ERROR).send([{ property: "stakeholders", constraints: { stakeholders: "Au moins un collaborateur est requis" } }]);
|
||||
response
|
||||
.status(HttpCodes.VALIDATION_ERROR)
|
||||
.send([{ property: "stakeholders", constraints: { stakeholders: "Au moins un collaborateur est requis" } }]);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -71,7 +73,7 @@ export default async function folderHandler(req: Request, response: Response, ne
|
||||
return;
|
||||
}
|
||||
|
||||
if(!officeFolder.stakeholders.find(stakeholder => stakeholder.uid === userId)) {
|
||||
if (!officeFolder.stakeholders.find((stakeholder) => stakeholder.uid === userId)) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this user");
|
||||
return;
|
||||
}
|
||||
@ -79,7 +81,7 @@ export default async function folderHandler(req: Request, response: Response, ne
|
||||
|
||||
next();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
|
@ -30,9 +30,8 @@ export default async function officeRoleHandler(req: Request, response: Response
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ export default async function userHandler(req: Request, response: Response, next
|
||||
|
||||
next();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ import { NextFunction, Request, Response } from "express";
|
||||
|
||||
export default async function roleHandler(req: Request, response: Response, next: NextFunction) {
|
||||
try {
|
||||
|
||||
const namespace = req.path && req.path.split("/")[3];
|
||||
const role = req.body.user.role;
|
||||
|
||||
@ -18,9 +17,8 @@ export default async function roleHandler(req: Request, response: Response, next
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
|
@ -17,9 +17,8 @@ export default async function ruleHandler(req: Request, response: Response, next
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
|
@ -1,14 +1,5 @@
|
||||
import { EOfficeStatus, Prisma, PrismaClient } from "@prisma/client";
|
||||
import {
|
||||
Address,
|
||||
Deed,
|
||||
DeedType,
|
||||
DocumentType,
|
||||
Office,
|
||||
OfficeRole,
|
||||
Role,
|
||||
Rule,
|
||||
} from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { Address, Deed, DeedType, DocumentType, Office, OfficeRole, Role, Rule } from "le-coffre-resources/dist/SuperAdmin";
|
||||
|
||||
import "module-alias/register";
|
||||
|
||||
@ -1327,10 +1318,10 @@ export default async function main() {
|
||||
deed.uid = deedCreated.uid;
|
||||
}
|
||||
|
||||
console.log(">MOCK DATA - Seeding completed!");
|
||||
console.info(">MOCK DATA - Seeding completed!");
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.log("Data already seeded, skiping");
|
||||
console.error(error);
|
||||
console.info("Data already seeded, skiping");
|
||||
}
|
||||
}
|
||||
main();
|
||||
|
@ -870,31 +870,20 @@ export default async function main() {
|
||||
"POST document-types",
|
||||
"POST deed-types",
|
||||
"PUT document-types",
|
||||
]
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Gestion de l'abonnement",
|
||||
uid: "94343601-04c8-44ef-afb9-3047597528a9",
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
rules : [
|
||||
"GET subscriptions",
|
||||
"POST subscriptions",
|
||||
"PUT subscriptions",
|
||||
"GET stripe",
|
||||
"POST stripe",
|
||||
]
|
||||
rules: ["GET subscriptions", "POST subscriptions", "PUT subscriptions", "GET stripe", "POST stripe"],
|
||||
},
|
||||
{
|
||||
name: "Intégration du RIB",
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
rules : [
|
||||
"PUT rib",
|
||||
"GET rib",
|
||||
"POST rib",
|
||||
"DELETE rib",
|
||||
]
|
||||
rules: ["PUT rib", "GET rib", "POST rib", "DELETE rib"],
|
||||
},
|
||||
];
|
||||
|
||||
@ -2188,10 +2177,10 @@ export default async function main() {
|
||||
officeFolder.uid = officeFolderCreated.uid;
|
||||
}
|
||||
|
||||
console.log(">MOCK DATA - Seeding completed!");
|
||||
console.info(">MOCK DATA - Seeding completed!");
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.log("Data already seeded, skiping");
|
||||
console.error(error);
|
||||
console.info("Data already seeded, skiping");
|
||||
}
|
||||
}
|
||||
main();
|
||||
|
@ -870,30 +870,19 @@ export default async function main() {
|
||||
"POST document-types",
|
||||
"POST deed-types",
|
||||
"PUT document-types",
|
||||
]
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Gestion de l'abonnement",
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
rules : [
|
||||
"GET subscriptions",
|
||||
"POST subscriptions",
|
||||
"PUT subscriptions",
|
||||
"GET stripe",
|
||||
"POST stripe",
|
||||
]
|
||||
rules: ["GET subscriptions", "POST subscriptions", "PUT subscriptions", "GET stripe", "POST stripe"],
|
||||
},
|
||||
{
|
||||
name: "Intégration du RIB",
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
rules : [
|
||||
"PUT rib",
|
||||
"GET rib",
|
||||
"POST rib",
|
||||
"DELETE rib",
|
||||
]
|
||||
rules: ["PUT rib", "GET rib", "POST rib", "DELETE rib"],
|
||||
},
|
||||
];
|
||||
|
||||
@ -2185,10 +2174,10 @@ export default async function main() {
|
||||
officeFolder.uid = officeFolderCreated.uid;
|
||||
}
|
||||
|
||||
console.log(">MOCK DATA - Seeding completed!");
|
||||
console.info(">MOCK DATA - Seeding completed!");
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.log("Data already seeded, skiping");
|
||||
console.error(error);
|
||||
console.info("Data already seeded, skiping");
|
||||
}
|
||||
}
|
||||
main();
|
||||
|
@ -6,7 +6,7 @@ import { BackendVariables } from "@Common/config/variables/Variables";
|
||||
import CronService from "@Services/common/CronService/CronService";
|
||||
|
||||
(async () => {
|
||||
console.log("Cron started");
|
||||
console.info("Cron started");
|
||||
|
||||
try {
|
||||
const variables = await Container.get(BackendVariables).validate();
|
||||
@ -17,7 +17,6 @@ import CronService from "@Services/common/CronService/CronService";
|
||||
Container.get(CronService).sendMails();
|
||||
Container.get(CronService).sendRecapMails();
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
import BaseService from "@Services/BaseService";
|
||||
import "reflect-metadata";
|
||||
import { Service } from "typedi";
|
||||
import { Prisma, Subscriptions } from "@prisma/client";
|
||||
import { ESubscriptionStatus, Prisma, Subscriptions } from "@prisma/client";
|
||||
import SubscriptionsRepository from "@Repositories/SubscriptionsRepository";
|
||||
import { Subscription } from "le-coffre-resources/dist/Admin";
|
||||
import SeatsService from "../SeatsService/SeatsService";
|
||||
import { EType } from "le-coffre-resources/dist/Admin/Subscription";
|
||||
|
||||
@Service()
|
||||
export default class SubscriptionsService extends BaseService {
|
||||
@ -42,7 +43,7 @@ export default class SubscriptionsService extends BaseService {
|
||||
*/
|
||||
public async update(uid: string, subscriptionEntity: Subscription): Promise<Subscriptions> {
|
||||
if (subscriptionEntity.type === "STANDARD") {
|
||||
const seats = await this.seatsService.get({ where: { subscription: { uid: uid } }, orderBy: {created_at: 'asc'} });
|
||||
const seats = await this.seatsService.get({ where: { subscription: { uid: uid } }, orderBy: { created_at: "asc" } });
|
||||
const seatsToKeep = subscriptionEntity.nb_seats;
|
||||
const seatsToDelete = seats.slice(seatsToKeep);
|
||||
|
||||
@ -60,4 +61,37 @@ export default class SubscriptionsService extends BaseService {
|
||||
public async delete(uid: string) {
|
||||
return this.subscriptionsRepository.delete(uid);
|
||||
}
|
||||
|
||||
public async isUserSubscribed(userUid: string, officeUid: string): Promise<boolean> {
|
||||
let isSubscribed = false;
|
||||
|
||||
const subscriptions = await this.get({ where: { office_uid: officeUid } });
|
||||
|
||||
if (!subscriptions || subscriptions.length === 0 || subscriptions[0]?.status === ESubscriptionStatus.INACTIVE) {
|
||||
isSubscribed = false;
|
||||
} else if (subscriptions[0]?.type === EType.Unlimited) {
|
||||
isSubscribed = true;
|
||||
} else {
|
||||
const hasSeat = await this.get({
|
||||
where: { status: ESubscriptionStatus.ACTIVE, seats: { some: { user_uid: userUid } } },
|
||||
});
|
||||
|
||||
if (hasSeat && hasSeat.length > 0) {
|
||||
isSubscribed = true;
|
||||
} else {
|
||||
const nbMaxSeats = subscriptions[0]!.nb_seats;
|
||||
|
||||
const nbCurrentSeats = await this.seatsService.get({ where: { subscription_uid: subscriptions[0]!.uid } });
|
||||
|
||||
//if nbMaxSeats < nbCurrentSeats, create a new seat for the user
|
||||
if (nbMaxSeats > nbCurrentSeats.length) {
|
||||
const seatAdded = await this.seatsService.create(userUid, subscriptions[0]!.uid);
|
||||
if (seatAdded) {
|
||||
isSubscribed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return isSubscribed;
|
||||
}
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ export default class Id360Service extends BaseService {
|
||||
},
|
||||
);
|
||||
|
||||
console.log(await resRecto.json(), await resVerso.json());
|
||||
console.info(await resRecto.json(), await resVerso.json());
|
||||
|
||||
await this.finalizeEnrollment(apiKey);
|
||||
}
|
||||
|
@ -90,6 +90,4 @@ export default class UsersService extends BaseService {
|
||||
public getUsersToBeChecked() {
|
||||
return this.userRepository.findManyToCheck();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user