Merge branch 'dev' into staging
This commit is contained in:
commit
34f338cd34
@ -169,7 +169,7 @@ export default class CustomersController extends ApiController {
|
|||||||
//success
|
//success
|
||||||
this.httpSuccess(response, customer);
|
this.httpSuccess(response, customer);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
this.httpValidationError(response, error);
|
this.httpValidationError(response, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ export default class AuthController extends ApiController {
|
|||||||
totpCodeUid: res.totpCode.uid,
|
totpCodeUid: res.totpCode.uid,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
this.httpInternalError(response);
|
this.httpInternalError(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ export default class AuthController extends ApiController {
|
|||||||
this.httpTooEarlyRequest(response, error.message);
|
this.httpTooEarlyRequest(response, error.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(error);
|
console.error(error);
|
||||||
this.httpInternalError(response);
|
this.httpInternalError(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ export default class AuthController extends ApiController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(error);
|
console.error(error);
|
||||||
this.httpInternalError(response);
|
this.httpInternalError(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -168,7 +168,7 @@ export default class AuthController extends ApiController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(error);
|
console.error(error);
|
||||||
this.httpInternalError(response);
|
this.httpInternalError(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -203,7 +203,7 @@ export default class AuthController extends ApiController {
|
|||||||
this.httpUnauthorized(response, error.message);
|
this.httpUnauthorized(response, error.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(error);
|
console.error(error);
|
||||||
this.httpInternalError(response);
|
this.httpInternalError(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -237,7 +237,7 @@ export default class AuthController extends ApiController {
|
|||||||
this.httpUnauthorized(response, error.message);
|
this.httpUnauthorized(response, error.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(error);
|
console.error(error);
|
||||||
this.httpInternalError(response);
|
this.httpInternalError(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ export default class DocumentsController extends ApiController {
|
|||||||
let query: Prisma.DocumentsFindManyArgs = {};
|
let query: Prisma.DocumentsFindManyArgs = {};
|
||||||
if (req.query["q"]) {
|
if (req.query["q"]) {
|
||||||
query = JSON.parse(req.query["q"] as string);
|
query = JSON.parse(req.query["q"] as string);
|
||||||
if(query.where?.uid) {
|
if (query.where?.uid) {
|
||||||
this.httpBadRequest(response, "You can't filter by uid");
|
this.httpBadRequest(response, "You can't filter by uid");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -74,7 +74,6 @@ export default class DocumentsController extends ApiController {
|
|||||||
if (req.query["q"]) {
|
if (req.query["q"]) {
|
||||||
query = JSON.parse(req.query["q"] as string);
|
query = JSON.parse(req.query["q"] as string);
|
||||||
if (query.folder) delete query.folder;
|
if (query.folder) delete query.folder;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const documentEntity = await this.documentsService.getByUid(uid, query);
|
const documentEntity = await this.documentsService.getByUid(uid, query);
|
||||||
@ -90,7 +89,7 @@ export default class DocumentsController extends ApiController {
|
|||||||
//success
|
//success
|
||||||
this.httpSuccess(response, document);
|
this.httpSuccess(response, document);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
this.httpInternalError(response);
|
this.httpInternalError(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ export default class CustomerController extends ApiController {
|
|||||||
const enrollment = await this.id360Service.createFranceConnectEnrollment();
|
const enrollment = await this.id360Service.createFranceConnectEnrollment();
|
||||||
this.httpSuccess(response, { enrollment });
|
this.httpSuccess(response, { enrollment });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
this.httpInternalError(response);
|
this.httpInternalError(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ export default class CustomerController extends ApiController {
|
|||||||
const refreshToken = this.authService.generateRefreshToken(payload);
|
const refreshToken = this.authService.generateRefreshToken(payload);
|
||||||
this.httpSuccess(response, { accessToken, refreshToken });
|
this.httpSuccess(response, { accessToken, refreshToken });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
this.httpInternalError(response);
|
this.httpInternalError(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ export default class CustomerController extends ApiController {
|
|||||||
const token = await this.id360Service.getId360Token();
|
const token = await this.id360Service.getId360Token();
|
||||||
this.httpSuccess(response, { token });
|
this.httpSuccess(response, { token });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
this.httpInternalError(response);
|
this.httpInternalError(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -109,7 +109,7 @@ export default class CustomerController extends ApiController {
|
|||||||
let accessToken;
|
let accessToken;
|
||||||
this.authService.verifyRefreshToken(token, (err, userPayload) => {
|
this.authService.verifyRefreshToken(token, (err, userPayload) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err);
|
console.error(err);
|
||||||
this.httpUnauthorized(response);
|
this.httpUnauthorized(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -123,7 +123,7 @@ export default class CustomerController extends ApiController {
|
|||||||
//success
|
//success
|
||||||
this.httpSuccess(response, { accessToken });
|
this.httpSuccess(response, { accessToken });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
this.httpInternalError(response);
|
this.httpInternalError(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,10 @@ export default class DocumentController extends ApiController {
|
|||||||
*/
|
*/
|
||||||
@Post("/api/v1/id360/enrollment-callback/")
|
@Post("/api/v1/id360/enrollment-callback/")
|
||||||
protected async getDocumentVerificationFromId360(req: Request, response: Response) {
|
protected async getDocumentVerificationFromId360(req: Request, response: Response) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.httpSuccess(response);
|
this.httpSuccess(response);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
this.httpInternalError(response);
|
this.httpInternalError(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -30,29 +29,28 @@ export default class DocumentController extends ApiController {
|
|||||||
|
|
||||||
@Post("/api/v1/id360/customer-callback/")
|
@Post("/api/v1/id360/customer-callback/")
|
||||||
protected async getCustomerVerificationFromId360(req: Request, response: Response) {
|
protected async getCustomerVerificationFromId360(req: Request, response: Response) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.httpSuccess(response);
|
this.httpSuccess(response);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
this.httpInternalError(response);
|
this.httpInternalError(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("/api/v1/id360/enrollment/:documentId")
|
@Post("/api/v1/id360/enrollment/:documentId")
|
||||||
protected async createEnrollment(req: Request, response: Response) {
|
protected async createEnrollment(req: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
const documentId = req.params["documentId"];
|
const documentId = req.params["documentId"];
|
||||||
if (!documentId) {
|
if (!documentId) {
|
||||||
this.httpBadRequest(response, "Missing document id");
|
this.httpBadRequest(response, "Missing document id");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await this.id360Service.createEnrollment(documentId!);
|
await this.id360Service.createEnrollment(documentId!);
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response);
|
this.httpSuccess(response);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
this.httpInternalError(response);
|
this.httpInternalError(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -9,29 +9,26 @@ import authHandler from "@App/middlewares/AuthHandler";
|
|||||||
@Controller()
|
@Controller()
|
||||||
@Service()
|
@Service()
|
||||||
export default class UserController extends ApiController {
|
export default class UserController extends ApiController {
|
||||||
constructor (private idNotService: IdNotService) {
|
constructor(private idNotService: IdNotService) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get("/api/v1/idnot/office/:uid/office-memberships", [authHandler, userHandler])
|
@Get("/api/v1/idnot/office/:uid/office-memberships", [authHandler, userHandler])
|
||||||
protected async getOfficeMemberships(req: Request, response: Response) {
|
protected async getOfficeMemberships(req: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
const uid = req.params["uid"];
|
const uid = req.params["uid"];
|
||||||
if (!uid) {
|
if (!uid) {
|
||||||
this.httpBadRequest(response, "uid is required");
|
this.httpBadRequest(response, "uid is required");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const officeMemberships = await this.idNotService.getOfficeMemberships(uid);
|
const officeMemberships = await this.idNotService.getOfficeMemberships(uid);
|
||||||
|
|
||||||
this.httpSuccess(response, officeMemberships);
|
this.httpSuccess(response, officeMemberships);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
this.httpInternalError(response);
|
this.httpInternalError(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,9 +8,6 @@ import IdNotService from "@Services/common/IdNotService/IdNotService";
|
|||||||
import User, { RulesGroup } from "le-coffre-resources/dist/Admin";
|
import User, { RulesGroup } from "le-coffre-resources/dist/Admin";
|
||||||
import UsersService from "@Services/super-admin/UsersService/UsersService";
|
import UsersService from "@Services/super-admin/UsersService/UsersService";
|
||||||
import SubscriptionsService from "@Services/admin/SubscriptionsService/SubscriptionsService.ts";
|
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";
|
import RulesGroupsService from "@Services/admin/RulesGroupsService/RulesGroupsService";
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@ -21,7 +18,6 @@ export default class UserController extends ApiController {
|
|||||||
private idNotService: IdNotService,
|
private idNotService: IdNotService,
|
||||||
private userService: UsersService,
|
private userService: UsersService,
|
||||||
private subscriptionsService: SubscriptionsService,
|
private subscriptionsService: SubscriptionsService,
|
||||||
private seatsService: SeatsService,
|
|
||||||
private rulesGroupsService: RulesGroupsService,
|
private rulesGroupsService: RulesGroupsService,
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
@ -57,8 +53,7 @@ export default class UserController extends ApiController {
|
|||||||
|
|
||||||
//Whitelist feature
|
//Whitelist feature
|
||||||
//Get user with contact
|
//Get user with contact
|
||||||
const prismaUser = await this.userService.getByUid(user.uid, { contact: true, role: true, office_membership: true});
|
const prismaUser = await this.userService.getByUid(user.uid, { contact: true, role: true, office_membership: true });
|
||||||
console.log(prismaUser);
|
|
||||||
|
|
||||||
if (!prismaUser) {
|
if (!prismaUser) {
|
||||||
this.httpNotFoundRequest(response, "user not found");
|
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
|
//Hydrate user to be able to use his contact
|
||||||
const userHydrated = User.hydrate<User>(prismaUser, { strategy: "excludeAll" });
|
const userHydrated = User.hydrate<User>(prismaUser, { strategy: "excludeAll" });
|
||||||
console.log(userHydrated);
|
|
||||||
|
|
||||||
if (!userHydrated.contact?.email || userHydrated.contact?.email === "") {
|
if (!userHydrated.contact?.email || userHydrated.contact?.email === "") {
|
||||||
this.httpUnauthorized(response, "Email not found");
|
this.httpUnauthorized(response, "Email not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let isSubscribed = false;
|
let isSubscribed = await this.subscriptionsService.isUserSubscribed(user.uid, userHydrated.office_membership?.uid!);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Check if user is whitelisted
|
//Check if user is whitelisted
|
||||||
// const isWhitelisted = await this.whitelistService.getByEmail(userHydrated.contact!.email);
|
// const isWhitelisted = await this.whitelistService.getByEmail(userHydrated.contact!.email);
|
||||||
@ -123,25 +84,18 @@ 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);
|
||||||
console.log(payload);
|
if (!payload) return;
|
||||||
if(!payload) return;
|
|
||||||
|
|
||||||
console.log(isSubscribed, userHydrated.role?.name);
|
if (!isSubscribed && (userHydrated.role?.name === "admin" || userHydrated.role?.name === "super-admin")) {
|
||||||
if(!isSubscribed && userHydrated.role?.name === "admin"){
|
const manageSubscriptionRulesEntity = await this.rulesGroupsService.get({
|
||||||
const manageSubscriptionRulesEntity = await this.rulesGroupsService.get({ where: { uid: "94343601-04c8-44ef-afb9-3047597528a9" }, include: { rules: true } });
|
where: { uid: "94343601-04c8-44ef-afb9-3047597528a9" },
|
||||||
|
include: { rules: true },
|
||||||
|
});
|
||||||
|
|
||||||
const manageSubscriptionRules = RulesGroup.hydrateArray<RulesGroup>(manageSubscriptionRulesEntity, { strategy: "excludeAll" });
|
const manageSubscriptionRules = RulesGroup.hydrateArray<RulesGroup>(manageSubscriptionRulesEntity, {
|
||||||
if(!manageSubscriptionRules[0]) return;
|
strategy: "excludeAll",
|
||||||
|
});
|
||||||
payload.rules = manageSubscriptionRules[0].rules!.map((rule) => rule.name) || [];
|
if (!manageSubscriptionRules[0]) return;
|
||||||
|
|
||||||
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" });
|
|
||||||
if(!manageSubscriptionRules[0]) return;
|
|
||||||
|
|
||||||
payload.rules = manageSubscriptionRules[0].rules!.map((rule) => rule.name) || [];
|
payload.rules = manageSubscriptionRules[0].rules!.map((rule) => rule.name) || [];
|
||||||
|
|
||||||
@ -158,7 +112,7 @@ export default class UserController extends ApiController {
|
|||||||
|
|
||||||
this.httpSuccess(response, { accessToken, refreshToken });
|
this.httpSuccess(response, { accessToken, refreshToken });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
this.httpInternalError(response);
|
this.httpInternalError(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -178,24 +132,43 @@ export default class UserController extends ApiController {
|
|||||||
let accessToken;
|
let accessToken;
|
||||||
this.authService.verifyRefreshToken(token, async (err, userPayload) => {
|
this.authService.verifyRefreshToken(token, async (err, userPayload) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err);
|
console.error(err);
|
||||||
this.httpUnauthorized(response);
|
this.httpUnauthorized(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const openId = (userPayload as IUserJwtPayload).openId.userId;
|
const openId = (userPayload as IUserJwtPayload).openId.userId;
|
||||||
if (!openId) return;
|
if (!openId) return;
|
||||||
const newUserPayload = await this.authService.getUserJwtPayload(openId.toString(), PROVIDER_OPENID.idNot);
|
const newUserPayload = (await this.authService.getUserJwtPayload(
|
||||||
const user = newUserPayload as IUserJwtPayload;
|
openId.toString(),
|
||||||
delete user.iat;
|
PROVIDER_OPENID.idNot,
|
||||||
delete user.exp;
|
)) as IUserJwtPayload;
|
||||||
accessToken = this.authService.generateAccessToken(user);
|
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 });
|
this.httpSuccess(response, { accessToken });
|
||||||
});
|
});
|
||||||
|
|
||||||
//success
|
//success
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
this.httpInternalError(response);
|
this.httpInternalError(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ export default class CustomersController extends ApiController {
|
|||||||
let query: Prisma.CustomersFindManyArgs = {};
|
let query: Prisma.CustomersFindManyArgs = {};
|
||||||
if (req.query["q"]) {
|
if (req.query["q"]) {
|
||||||
query = JSON.parse(req.query["q"] as string);
|
query = JSON.parse(req.query["q"] as string);
|
||||||
if(query.where?.uid) {
|
if (query.where?.uid) {
|
||||||
this.httpBadRequest(response, "You can't filter by uid");
|
this.httpBadRequest(response, "You can't filter by uid");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -168,7 +168,7 @@ export default class CustomersController extends ApiController {
|
|||||||
//success
|
//success
|
||||||
this.httpSuccess(response, customer);
|
this.httpSuccess(response, customer);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
this.httpValidationError(response, error);
|
this.httpValidationError(response, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,7 @@ export default class CustomersController extends ApiController {
|
|||||||
//success
|
//success
|
||||||
this.httpSuccess(response, customer);
|
this.httpSuccess(response, customer);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
this.httpValidationError(response, error);
|
this.httpValidationError(response, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,8 @@ export default function authHandler(req: Request, response: Response, next: Next
|
|||||||
req.body.user = userPayload;
|
req.body.user = userPayload;
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ export default async function documentHandler(req: Request, response: Response,
|
|||||||
|
|
||||||
if (document?.depositor_uid != customerId) {
|
if (document?.depositor_uid != customerId) {
|
||||||
const customerService = Container.get(CustomersService);
|
const customerService = Container.get(CustomersService);
|
||||||
const customers = await customerService.get({where: {contact: { email: customerEmail}}});
|
const customers = await customerService.get({ where: { contact: { email: customerEmail } } });
|
||||||
if (customers && !customers.find((customer) => customer.uid === document?.depositor_uid)) {
|
if (customers && !customers.find((customer) => customer.uid === document?.depositor_uid)) {
|
||||||
response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this depositor");
|
response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this depositor");
|
||||||
return;
|
return;
|
||||||
@ -66,7 +66,7 @@ export default async function documentHandler(req: Request, response: Response,
|
|||||||
|
|
||||||
next();
|
next();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,9 @@ export default async function customerHandler(req: Request, response: Response,
|
|||||||
|
|
||||||
if (uid) {
|
if (uid) {
|
||||||
const customerService = Container.get(CustomersService);
|
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]) {
|
if (!customer[0]) {
|
||||||
response.status(HttpCodes.NOT_FOUND).send("Customer not found");
|
response.status(HttpCodes.NOT_FOUND).send("Customer not found");
|
||||||
@ -19,9 +21,8 @@ export default async function customerHandler(req: Request, response: Response,
|
|||||||
}
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -42,9 +42,8 @@ export default async function deedHandler(req: Request, response: Response, next
|
|||||||
}
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ export default async function deedTypeHandler(req: Request, response: Response,
|
|||||||
|
|
||||||
next();
|
next();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -57,16 +57,15 @@ export default async function documentHandler(req: Request, response: Response,
|
|||||||
return;
|
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");
|
response.sendStatus(HttpCodes.UNAUTHORIZED).send("Unauthorized with this user");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,9 @@ export default async function documentTypeHandler(req: Request, response: Respon
|
|||||||
where: { AND: [{ name: { equals: name, mode: "insensitive" } }, { office: { uid: officeId } }] },
|
where: { AND: [{ name: { equals: name, mode: "insensitive" } }, { office: { uid: officeId } }] },
|
||||||
});
|
});
|
||||||
if (documentType[0] && (!uid || documentType[0].uid != uid)) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -42,9 +44,8 @@ export default async function documentTypeHandler(req: Request, response: Respon
|
|||||||
}
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ export default async function fileHandler(req: Request, response: Response, next
|
|||||||
|
|
||||||
next();
|
next();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -19,20 +19,22 @@ export default async function folderHandler(req: Request, response: Response, ne
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(folderNumber) {
|
if (folderNumber) {
|
||||||
const officeFolderService = Container.get(OfficeFoldersService);
|
const officeFolderService = Container.get(OfficeFoldersService);
|
||||||
const sameFolderNumber = await officeFolderService.get({
|
const sameFolderNumber = await officeFolderService.get({
|
||||||
where: { AND: [{ folder_number: folderNumber }, { office_uid: officeId }] },
|
where: { AND: [{ folder_number: folderNumber }, { office_uid: officeId }] },
|
||||||
});
|
});
|
||||||
if(sameFolderNumber[0] && (!uid || uid != sameFolderNumber[0]?.uid)) {
|
if (sameFolderNumber[0] && (!uid || uid != sameFolderNumber[0]?.uid)) {
|
||||||
const error = [{property: "folder_number", constraints: { folder_number: "Numéro de dossier déjà utilisé" } }];
|
const error = [{ property: "folder_number", constraints: { folder_number: "Numéro de dossier déjà utilisé" } }];
|
||||||
response.status(HttpCodes.VALIDATION_ERROR).send(error);
|
response.status(HttpCodes.VALIDATION_ERROR).send(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(stakeHolders && stakeHolders.length === 0) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +45,7 @@ export default async function folderHandler(req: Request, response: Response, ne
|
|||||||
response.status(HttpCodes.NOT_FOUND).send("Deed type not found");
|
response.status(HttpCodes.NOT_FOUND).send("Deed type not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(deedTypeWithOffice.archived_at) {
|
if (deedTypeWithOffice.archived_at) {
|
||||||
response.status(HttpCodes.FORBIDDEN).send("Deed type is archived");
|
response.status(HttpCodes.FORBIDDEN).send("Deed type is archived");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -54,7 +56,7 @@ export default async function folderHandler(req: Request, response: Response, ne
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (uid) {
|
if (uid) {
|
||||||
if(uid === "download") {
|
if (uid === "download") {
|
||||||
uid = req.path && req.path.split("/")[6];
|
uid = req.path && req.path.split("/")[6];
|
||||||
}
|
}
|
||||||
const officeFolderService = Container.get(OfficeFoldersService);
|
const officeFolderService = Container.get(OfficeFoldersService);
|
||||||
@ -71,7 +73,7 @@ export default async function folderHandler(req: Request, response: Response, ne
|
|||||||
return;
|
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");
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this user");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -79,7 +81,7 @@ export default async function folderHandler(req: Request, response: Response, ne
|
|||||||
|
|
||||||
next();
|
next();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -30,9 +30,8 @@ export default async function officeRoleHandler(req: Request, response: Response
|
|||||||
}
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ export default async function userHandler(req: Request, response: Response, next
|
|||||||
|
|
||||||
next();
|
next();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,10 @@ import { NextFunction, Request, Response } from "express";
|
|||||||
|
|
||||||
export default async function roleHandler(req: Request, response: Response, next: NextFunction) {
|
export default async function roleHandler(req: Request, response: Response, next: NextFunction) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const namespace = req.path && req.path.split("/")[3];
|
const namespace = req.path && req.path.split("/")[3];
|
||||||
const role = req.body.user.role;
|
const role = req.body.user.role;
|
||||||
|
|
||||||
if(!role) {
|
if (!role) {
|
||||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized without role");
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized without role");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -18,9 +17,8 @@ export default async function roleHandler(req: Request, response: Response, next
|
|||||||
}
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,8 @@ export default async function ruleHandler(req: Request, response: Response, next
|
|||||||
}
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,5 @@
|
|||||||
import { EOfficeStatus, Prisma, PrismaClient } from "@prisma/client";
|
import { EOfficeStatus, Prisma, PrismaClient } from "@prisma/client";
|
||||||
import {
|
import { Address, Deed, DeedType, DocumentType, Office, OfficeRole, Role, Rule } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
Address,
|
|
||||||
Deed,
|
|
||||||
DeedType,
|
|
||||||
DocumentType,
|
|
||||||
Office,
|
|
||||||
OfficeRole,
|
|
||||||
Role,
|
|
||||||
Rule,
|
|
||||||
} from "le-coffre-resources/dist/SuperAdmin";
|
|
||||||
|
|
||||||
import "module-alias/register";
|
import "module-alias/register";
|
||||||
|
|
||||||
@ -1280,7 +1271,7 @@ export default async function main() {
|
|||||||
const createArgs: Prisma.DeedTypesCreateArgs = {
|
const createArgs: Prisma.DeedTypesCreateArgs = {
|
||||||
data: {
|
data: {
|
||||||
name: deedType.name,
|
name: deedType.name,
|
||||||
description: deedType.description || "" ,
|
description: deedType.description || "",
|
||||||
office: {
|
office: {
|
||||||
connect: {
|
connect: {
|
||||||
uid: deedType.office!.uid,
|
uid: deedType.office!.uid,
|
||||||
@ -1327,10 +1318,10 @@ export default async function main() {
|
|||||||
deed.uid = deedCreated.uid;
|
deed.uid = deedCreated.uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(">MOCK DATA - Seeding completed!");
|
console.info(">MOCK DATA - Seeding completed!");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
console.log("Data already seeded, skiping");
|
console.info("Data already seeded, skiping");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
main();
|
main();
|
||||||
|
@ -870,31 +870,20 @@ export default async function main() {
|
|||||||
"POST document-types",
|
"POST document-types",
|
||||||
"POST deed-types",
|
"POST deed-types",
|
||||||
"PUT document-types",
|
"PUT document-types",
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Gestion de l'abonnement",
|
name: "Gestion de l'abonnement",
|
||||||
uid: "94343601-04c8-44ef-afb9-3047597528a9",
|
uid: "94343601-04c8-44ef-afb9-3047597528a9",
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
rules : [
|
rules: ["GET subscriptions", "POST subscriptions", "PUT subscriptions", "GET stripe", "POST stripe"],
|
||||||
"GET subscriptions",
|
|
||||||
"POST subscriptions",
|
|
||||||
"PUT subscriptions",
|
|
||||||
"GET stripe",
|
|
||||||
"POST stripe",
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Intégration du RIB",
|
name: "Intégration du RIB",
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
rules : [
|
rules: ["PUT rib", "GET rib", "POST rib", "DELETE rib"],
|
||||||
"PUT rib",
|
|
||||||
"GET rib",
|
|
||||||
"POST rib",
|
|
||||||
"DELETE rib",
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -2188,10 +2177,10 @@ export default async function main() {
|
|||||||
officeFolder.uid = officeFolderCreated.uid;
|
officeFolder.uid = officeFolderCreated.uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(">MOCK DATA - Seeding completed!");
|
console.info(">MOCK DATA - Seeding completed!");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
console.log("Data already seeded, skiping");
|
console.info("Data already seeded, skiping");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
main();
|
main();
|
||||||
|
@ -870,30 +870,19 @@ export default async function main() {
|
|||||||
"POST document-types",
|
"POST document-types",
|
||||||
"POST deed-types",
|
"POST deed-types",
|
||||||
"PUT document-types",
|
"PUT document-types",
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Gestion de l'abonnement",
|
name: "Gestion de l'abonnement",
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
rules : [
|
rules: ["GET subscriptions", "POST subscriptions", "PUT subscriptions", "GET stripe", "POST stripe"],
|
||||||
"GET subscriptions",
|
|
||||||
"POST subscriptions",
|
|
||||||
"PUT subscriptions",
|
|
||||||
"GET stripe",
|
|
||||||
"POST stripe",
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Intégration du RIB",
|
name: "Intégration du RIB",
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
rules : [
|
rules: ["PUT rib", "GET rib", "POST rib", "DELETE rib"],
|
||||||
"PUT rib",
|
|
||||||
"GET rib",
|
|
||||||
"POST rib",
|
|
||||||
"DELETE rib",
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -2185,10 +2174,10 @@ export default async function main() {
|
|||||||
officeFolder.uid = officeFolderCreated.uid;
|
officeFolder.uid = officeFolderCreated.uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(">MOCK DATA - Seeding completed!");
|
console.info(">MOCK DATA - Seeding completed!");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
console.log("Data already seeded, skiping");
|
console.info("Data already seeded, skiping");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
main();
|
main();
|
||||||
|
@ -6,18 +6,17 @@ import { BackendVariables } from "@Common/config/variables/Variables";
|
|||||||
import CronService from "@Services/common/CronService/CronService";
|
import CronService from "@Services/common/CronService/CronService";
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
console.log("Cron started");
|
console.info("Cron started");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const variables = await Container.get(BackendVariables).validate();
|
const variables = await Container.get(BackendVariables).validate();
|
||||||
Container.get(CronService).archiveFiles();
|
Container.get(CronService).archiveFiles();
|
||||||
await Container.get(CronService).updateUsers();
|
await Container.get(CronService).updateUsers();
|
||||||
Container.get(CronService).checkDocumentsExpiration();
|
Container.get(CronService).checkDocumentsExpiration();
|
||||||
if(variables.ENV !== "dev"){
|
if (variables.ENV !== "dev") {
|
||||||
Container.get(CronService).sendMails();
|
Container.get(CronService).sendMails();
|
||||||
Container.get(CronService).sendRecapMails();
|
Container.get(CronService).sendRecapMails();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import BaseService from "@Services/BaseService";
|
import BaseService from "@Services/BaseService";
|
||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import { Prisma, Subscriptions } from "@prisma/client";
|
import { ESubscriptionStatus, Prisma, Subscriptions } from "@prisma/client";
|
||||||
import SubscriptionsRepository from "@Repositories/SubscriptionsRepository";
|
import SubscriptionsRepository from "@Repositories/SubscriptionsRepository";
|
||||||
import { Subscription } from "le-coffre-resources/dist/Admin";
|
import { Subscription } from "le-coffre-resources/dist/Admin";
|
||||||
import SeatsService from "../SeatsService/SeatsService";
|
import SeatsService from "../SeatsService/SeatsService";
|
||||||
|
import { EType } from "le-coffre-resources/dist/Admin/Subscription";
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class SubscriptionsService extends BaseService {
|
export default class SubscriptionsService extends BaseService {
|
||||||
@ -41,8 +42,8 @@ export default class SubscriptionsService extends BaseService {
|
|||||||
* @throws {Error} If subscription cannot be modified
|
* @throws {Error} If subscription cannot be modified
|
||||||
*/
|
*/
|
||||||
public async update(uid: string, subscriptionEntity: Subscription): Promise<Subscriptions> {
|
public async update(uid: string, subscriptionEntity: Subscription): Promise<Subscriptions> {
|
||||||
if(subscriptionEntity.type === "STANDARD"){
|
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 seatsToKeep = subscriptionEntity.nb_seats;
|
||||||
const seatsToDelete = seats.slice(seatsToKeep);
|
const seatsToDelete = seats.slice(seatsToKeep);
|
||||||
|
|
||||||
@ -60,4 +61,37 @@ export default class SubscriptionsService extends BaseService {
|
|||||||
public async delete(uid: string) {
|
public async delete(uid: string) {
|
||||||
return this.subscriptionsRepository.delete(uid);
|
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);
|
await this.finalizeEnrollment(apiKey);
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,4 @@ export default class UsersService extends BaseService {
|
|||||||
public getUsersToBeChecked() {
|
public getUsersToBeChecked() {
|
||||||
return this.userRepository.findManyToCheck();
|
return this.userRepository.findManyToCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user