merging dev in staging (#59)
This commit is contained in:
commit
43de428338
@ -48,6 +48,9 @@ jobs:
|
|||||||
--create-namespace
|
--create-namespace
|
||||||
--set lecoffreBack.image.repository='rg.fr-par.scw.cloud/lecoffre/back'
|
--set lecoffreBack.image.repository='rg.fr-par.scw.cloud/lecoffre/back'
|
||||||
--set lecoffreBack.image.tag=${CIRCLE_SHA1:0:7}
|
--set lecoffreBack.image.tag=${CIRCLE_SHA1:0:7}
|
||||||
|
--set lecoffreCron.image.repository='rg.fr-par.scw.cloud/lecoffre/back'
|
||||||
|
--set lecoffreCron.image.tag=${CIRCLE_SHA1:0:7}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
workflows:
|
workflows:
|
||||||
|
@ -4,7 +4,7 @@ scwSecretKey: AgCgjF5QEzxT3GYTS5B6cmQ0e+0/qFWzKaUDSi+Vjc7RoameuvaIJvTXMBkS3he1oy
|
|||||||
|
|
||||||
lecoffreBack:
|
lecoffreBack:
|
||||||
serviceAccountName: lecoffre-back-sa
|
serviceAccountName: lecoffre-back-sa
|
||||||
command: "export $(xargs </etc/env/.env) && npm run api:start"
|
command: "'sh', '-c', 'export $(xargs </etc/env/.env) && npm run api:start'"
|
||||||
envSecrets: ppd-env
|
envSecrets: ppd-env
|
||||||
imagePullSecrets:
|
imagePullSecrets:
|
||||||
- name: docker-pull-secret
|
- name: docker-pull-secret
|
||||||
@ -32,3 +32,23 @@ lecoffreBack:
|
|||||||
- key: .env
|
- key: .env
|
||||||
scwID: "id:a131edea-84e0-49d6-b4a8-20ab417220c9"
|
scwID: "id:a131edea-84e0-49d6-b4a8-20ab417220c9"
|
||||||
|
|
||||||
|
lecoffreCron:
|
||||||
|
serviceAccountName: lecoffre-cron-sa
|
||||||
|
envSecrets: stg-env
|
||||||
|
command: "'sh', '-c', 'export $(xargs </etc/env/.env) && npm run cron'"
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: docker-pull-secret
|
||||||
|
image:
|
||||||
|
pullPolicy: Always
|
||||||
|
repository: "rg.fr-par.scw.cloud/lecoffre/back"
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 200m
|
||||||
|
memory: 1Gi
|
||||||
|
limits:
|
||||||
|
memory: 2Gi
|
||||||
|
# key is name of the environment variable, scwID is the secret ID in SCW with "id:" in front
|
||||||
|
env:
|
||||||
|
- key: .env
|
||||||
|
scwID: "id:2be9510b-bb1f-4fbe-ab3e-3dc11fb49051"
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ scwSecretKey: AgBG2y7uQuap+2akNPGFxpCR+l0INO6Wxez5qljtY6t71GFGhJLYN9ZfefflKcFzD2
|
|||||||
|
|
||||||
lecoffreBack:
|
lecoffreBack:
|
||||||
serviceAccountName: lecoffre-back-sa
|
serviceAccountName: lecoffre-back-sa
|
||||||
command: "export $(xargs </etc/env/.env) && npm run api:start"
|
command: "'sh', '-c', 'export $(xargs </etc/env/.env) && npm run api:start'"
|
||||||
envSecrets: prd-env
|
envSecrets: prd-env
|
||||||
imagePullSecrets:
|
imagePullSecrets:
|
||||||
- name: docker-pull-secret
|
- name: docker-pull-secret
|
||||||
@ -32,3 +32,23 @@ lecoffreBack:
|
|||||||
- key: .env
|
- key: .env
|
||||||
scwID: "id:a131edea-84e0-49d6-b4a8-20ab417220c9"
|
scwID: "id:a131edea-84e0-49d6-b4a8-20ab417220c9"
|
||||||
|
|
||||||
|
lecoffreCron:
|
||||||
|
serviceAccountName: lecoffre-cron-sa
|
||||||
|
envSecrets: stg-env
|
||||||
|
command: "'sh', '-c', 'export $(xargs </etc/env/.env) && npm run cron'"
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: docker-pull-secret
|
||||||
|
image:
|
||||||
|
pullPolicy: Always
|
||||||
|
repository: "rg.fr-par.scw.cloud/lecoffre/back"
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 200m
|
||||||
|
memory: 1Gi
|
||||||
|
limits:
|
||||||
|
memory: 2Gi
|
||||||
|
# key is name of the environment variable, scwID is the secret ID in SCW with "id:" in front
|
||||||
|
env:
|
||||||
|
- key: .env
|
||||||
|
scwID: "id:2be9510b-bb1f-4fbe-ab3e-3dc11fb49051"
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ scwSecretKey: AgChoEnPitXp4Ny/rVMEcevaWKNVpyj2cJYAcq+yFqKwVwnLB+ffDvwqz9XBHu+6d4
|
|||||||
lecoffreBack:
|
lecoffreBack:
|
||||||
serviceAccountName: lecoffre-back-sa
|
serviceAccountName: lecoffre-back-sa
|
||||||
envSecrets: stg-env
|
envSecrets: stg-env
|
||||||
command: "export $(xargs </etc/env/.env) && npm run api:start"
|
command: "'sh', '-c', 'export $(xargs </etc/env/.env) && npm run api:start'"
|
||||||
imagePullSecrets:
|
imagePullSecrets:
|
||||||
- name: docker-pull-secret
|
- name: docker-pull-secret
|
||||||
image:
|
image:
|
||||||
@ -33,4 +33,24 @@ lecoffreBack:
|
|||||||
- key: .env
|
- key: .env
|
||||||
scwID: "id:2be9510b-bb1f-4fbe-ab3e-3dc11fb49051"
|
scwID: "id:2be9510b-bb1f-4fbe-ab3e-3dc11fb49051"
|
||||||
|
|
||||||
|
lecoffreCron:
|
||||||
|
serviceAccountName: lecoffre-cron-sa
|
||||||
|
envSecrets: stg-env
|
||||||
|
command: "'sh', '-c', 'export $(xargs </etc/env/.env) && npm run cron'"
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: docker-pull-secret
|
||||||
|
image:
|
||||||
|
pullPolicy: Always
|
||||||
|
repository: "rg.fr-par.scw.cloud/lecoffre/back"
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 200m
|
||||||
|
memory: 1Gi
|
||||||
|
limits:
|
||||||
|
memory: 2Gi
|
||||||
|
# key is name of the environment variable, scwID is the secret ID in SCW with "id:" in front
|
||||||
|
env:
|
||||||
|
- key: .env
|
||||||
|
scwID: "id:2be9510b-bb1f-4fbe-ab3e-3dc11fb49051"
|
||||||
|
|
||||||
|
|
||||||
|
37
devops/templates/lecoffre-cron.yaml
Normal file
37
devops/templates/lecoffre-cron.yaml
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: lecoffre-cron
|
||||||
|
labels:
|
||||||
|
app: lecoffre-cron
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: lecoffre-cron
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
labels:
|
||||||
|
app: lecoffre-cron
|
||||||
|
spec:
|
||||||
|
serviceAccountName: {{ .Values.lecoffreCron.serviceAccountName }}
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: docker-pull-secret
|
||||||
|
containers:
|
||||||
|
- name: lecoffre-cron
|
||||||
|
image: "{{ .Values.lecoffreCron.image.repository }}:{{ .Values.lecoffreCron.image.tag }}"
|
||||||
|
{{if .Values.lecoffreCron.resources}}
|
||||||
|
resources:
|
||||||
|
{{toYaml .Values.lecoffreCron.resources | indent 10}}
|
||||||
|
{{end}}
|
||||||
|
imagePullPolicy: {{ .Values.lecoffreCron.image.pullPolicy }}
|
||||||
|
command: [{{ .Values.lecoffreCron.command }}]
|
||||||
|
volumeMounts:
|
||||||
|
- name: secret-volume
|
||||||
|
mountPath: /etc/env
|
||||||
|
volumes:
|
||||||
|
- name: secret-volume
|
||||||
|
secret:
|
||||||
|
secretName: {{ .Values.lecoffreCron.envSecrets }}
|
@ -12,3 +12,19 @@ metadata:
|
|||||||
annotations:
|
annotations:
|
||||||
kubernetes.io/service-account.name: {{ .Values.lecoffreBack.serviceAccountName }}
|
kubernetes.io/service-account.name: {{ .Values.lecoffreBack.serviceAccountName }}
|
||||||
type: kubernetes.io/service-account-token
|
type: kubernetes.io/service-account-token
|
||||||
|
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: {{ .Values.lecoffreCron.serviceAccountName }}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: {{ .Values.lecoffreCron.serviceAccountName }}-token
|
||||||
|
annotations:
|
||||||
|
kubernetes.io/service-account.name: {{ .Values.lecoffreCron.serviceAccountName }}
|
||||||
|
type: kubernetes.io/service-account-token
|
79
src/app/api/customer/CustomersController.ts
Normal file
79
src/app/api/customer/CustomersController.ts
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
import { Response, Request } from "express";
|
||||||
|
import { Controller, Get } from "@ControllerPattern/index";
|
||||||
|
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||||
|
import CustomersService from "@Services/customer/CustomersService/CustomersService";
|
||||||
|
import { Service } from "typedi";
|
||||||
|
import Customer from "le-coffre-resources/dist/Customer";
|
||||||
|
import authHandler from "@App/middlewares/AuthHandler";
|
||||||
|
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||||
|
|
||||||
|
@Controller()
|
||||||
|
@Service()
|
||||||
|
export default class CustomersController extends ApiController {
|
||||||
|
constructor(private customersService: CustomersService) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Get all customers
|
||||||
|
*/
|
||||||
|
@Get("/api/v1/customer/customers")
|
||||||
|
protected async get(req: Request, response: Response) {
|
||||||
|
try {
|
||||||
|
//get query
|
||||||
|
let query;
|
||||||
|
if (req.query["q"]) {
|
||||||
|
query = JSON.parse(req.query["q"] as string);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//call service to get prisma entity
|
||||||
|
const customersEntities = await this.customersService.get(query);
|
||||||
|
|
||||||
|
//Hydrate ressource with prisma entity
|
||||||
|
const customers = Customer.hydrateArray<Customer>(customersEntities, { strategy: "excludeAll" });
|
||||||
|
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, customers);
|
||||||
|
} catch (error) {
|
||||||
|
this.httpInternalError(response, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Get a specific customer by uid
|
||||||
|
*/
|
||||||
|
@Get("/api/v1/customer/customers/:uid", [authHandler, ruleHandler])
|
||||||
|
protected async getOneByUid(req: Request, response: Response) {
|
||||||
|
try {
|
||||||
|
const uid = req.params["uid"];
|
||||||
|
if (!uid) {
|
||||||
|
this.httpBadRequest(response, "No uid provided");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let query;
|
||||||
|
if (req.query["q"]) {
|
||||||
|
query = JSON.parse(req.query["q"] as string);
|
||||||
|
}
|
||||||
|
|
||||||
|
const customerEntity = await this.customersService.getByUid(uid, query);
|
||||||
|
|
||||||
|
if (!customerEntity) {
|
||||||
|
this.httpNotFoundRequest(response, "customer not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Hydrate ressource with prisma entity
|
||||||
|
const customer = Customer.hydrate<Customer>(customerEntity, { strategy: "excludeAll" });
|
||||||
|
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, customer);
|
||||||
|
} catch (error) {
|
||||||
|
this.httpInternalError(response, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -27,13 +27,19 @@ 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);
|
||||||
}
|
}
|
||||||
const customerId: string = req.body.user.customerId;
|
|
||||||
const customerWhereInput: Prisma.DocumentsWhereInput ={ depositor: { uid: customerId } };
|
|
||||||
query.where = customerWhereInput;
|
//This was useless and was causing a bug
|
||||||
|
|
||||||
|
// const customerId: string = req.body.user.customerId;
|
||||||
|
// const customerWhereInput: Prisma.DocumentsWhereInput ={ depositor: { uid: customerId } };
|
||||||
|
// query.where = customerWhereInput;
|
||||||
|
|
||||||
|
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
const documentEntities: Documents[] = await this.documentsService.get(query);
|
const documentEntities: Documents[] = await this.documentsService.get(query);
|
||||||
|
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const documents = Document.hydrateArray<Document>(documentEntities, { strategy: "excludeAll" });
|
const documents = Document.hydrateArray<Document>(documentEntities, { strategy: "excludeAll" });
|
||||||
|
|
||||||
|
113
src/app/api/customer/OfficeFoldersController.ts
Normal file
113
src/app/api/customer/OfficeFoldersController.ts
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
import { Response, Request } from "express";
|
||||||
|
import { Controller, Get } from "@ControllerPattern/index";
|
||||||
|
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||||
|
import OfficeFoldersService from "@Services/customer/OfficeFoldersService/OfficeFoldersService";
|
||||||
|
import { Service } from "typedi";
|
||||||
|
import { OfficeFolders, Prisma } from "@prisma/client";
|
||||||
|
import { OfficeFolder } from "le-coffre-resources/dist/Customer";
|
||||||
|
// import authHandler from "@App/middlewares/AuthHandler";
|
||||||
|
// import ruleHandler from "@App/middlewares/RulesHandler";
|
||||||
|
// import folderHandler from "@App/middlewares/OfficeMembershipHandlers/FolderHandler";
|
||||||
|
|
||||||
|
@Controller()
|
||||||
|
@Service()
|
||||||
|
export default class OfficeFoldersController extends ApiController {
|
||||||
|
constructor(private officeFoldersService: OfficeFoldersService) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Get all folders
|
||||||
|
*/
|
||||||
|
@Get("/api/v1/customer/folders")
|
||||||
|
protected async get(req: Request, response: Response) {
|
||||||
|
try {
|
||||||
|
//get query
|
||||||
|
let query: Prisma.OfficeFoldersFindManyArgs = {};
|
||||||
|
if (req.query["q"]) {
|
||||||
|
query = JSON.parse(req.query["q"] as string);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (req.query["search"] && typeof req.query["search"] === "string") {
|
||||||
|
const filter = req.query["search"];
|
||||||
|
query = {
|
||||||
|
where: {
|
||||||
|
OR: [
|
||||||
|
{
|
||||||
|
name: { contains: filter, mode: "insensitive" },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
folder_number: { contains: filter, mode: "insensitive" },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
customers: {
|
||||||
|
some: {
|
||||||
|
contact: {
|
||||||
|
OR: [
|
||||||
|
{ first_name: { contains: filter, mode: "insensitive" } },
|
||||||
|
{ last_name: { contains: filter, mode: "insensitive" } },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const officeWhereInput: Prisma.OfficesWhereInput = {};
|
||||||
|
if (!query.where) query.where = { office: officeWhereInput };
|
||||||
|
query.where.office = officeWhereInput;
|
||||||
|
|
||||||
|
//call service to get prisma entity
|
||||||
|
const officeFolderEntities: OfficeFolders[] = await this.officeFoldersService.get(query);
|
||||||
|
|
||||||
|
//Hydrate ressource with prisma entity
|
||||||
|
const officeFolders = OfficeFolder.hydrateArray<OfficeFolder>(officeFolderEntities, {
|
||||||
|
strategy: "excludeAll",
|
||||||
|
});
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, officeFolders);
|
||||||
|
} catch (error) {
|
||||||
|
this.httpInternalError(response, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Get a specific folder by uid
|
||||||
|
* @returns IFolder
|
||||||
|
*/
|
||||||
|
@Get("/api/v1/customer/folders/:uid")
|
||||||
|
protected async getOneByUid(req: Request, response: Response) {
|
||||||
|
try {
|
||||||
|
const uid = req.params["uid"];
|
||||||
|
if (!uid) {
|
||||||
|
this.httpBadRequest(response, "No uid provided");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let query;
|
||||||
|
if (req.query["q"]) {
|
||||||
|
query = JSON.parse(req.query["q"] as string);
|
||||||
|
}
|
||||||
|
|
||||||
|
const officeFolderEntity = await this.officeFoldersService.getByUid(uid, query);
|
||||||
|
|
||||||
|
if (!officeFolderEntity) {
|
||||||
|
this.httpNotFoundRequest(response, "folder not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Hydrate ressource with prisma entity
|
||||||
|
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntity, { strategy: "excludeAll" });
|
||||||
|
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, officeFolder);
|
||||||
|
} catch (error) {
|
||||||
|
this.httpInternalError(response, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -21,7 +21,6 @@ export default class CustomerController extends ApiController {
|
|||||||
const payload = await this.authService.getCustomerJwtPayload(email);
|
const payload = await this.authService.getCustomerJwtPayload(email);
|
||||||
const accessToken = this.authService.generateAccessToken(payload);
|
const accessToken = this.authService.generateAccessToken(payload);
|
||||||
const refreshToken = this.authService.generateRefreshToken(payload);
|
const refreshToken = this.authService.generateRefreshToken(payload);
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, { accessToken, refreshToken });
|
this.httpSuccess(response, { accessToken, refreshToken });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -42,7 +42,7 @@ export default class UserController extends ApiController {
|
|||||||
const id = req.params["idnot"];
|
const id = req.params["idnot"];
|
||||||
if (!id) throw new Error("idnot is required");
|
if (!id) throw new Error("idnot is required");
|
||||||
|
|
||||||
const payload = await this.authService.getUserJwtPayload(id!);
|
const payload = await this.authService.getUserJwtPayload(id);
|
||||||
const accessToken = this.authService.generateAccessToken(payload);
|
const accessToken = this.authService.generateAccessToken(payload);
|
||||||
const refreshToken = this.authService.generateRefreshToken(payload);
|
const refreshToken = this.authService.generateRefreshToken(payload);
|
||||||
|
|
||||||
|
@ -40,8 +40,6 @@ export default class DocumentsController extends ApiController {
|
|||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
|
|
||||||
const documentEntities = await this.documentsService.get(query);
|
const documentEntities = await this.documentsService.get(query);
|
||||||
console.log(documentEntities);
|
|
||||||
|
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const documents = Document.hydrateArray<Document>(documentEntities, { strategy: "excludeAll" });
|
const documents = Document.hydrateArray<Document>(documentEntities, { strategy: "excludeAll" });
|
||||||
|
@ -76,7 +76,7 @@ export default class VotesController extends ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Delete a specific folder
|
* @description Delete a specific vote
|
||||||
*/
|
*/
|
||||||
@Delete("/api/v1/super-admin/votes/:uid", [authHandler])
|
@Delete("/api/v1/super-admin/votes/:uid", [authHandler])
|
||||||
protected async delete(req: Request, response: Response) {
|
protected async delete(req: Request, response: Response) {
|
||||||
@ -94,6 +94,11 @@ export default class VotesController extends ApiController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (voteFound.voter_uid !== req.body.user.userId) {
|
||||||
|
this.httpUnauthorized(response, "Can't delete a vote that's not yours");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
const votetEntity: Votes = await this.votesService.delete(uid);
|
const votetEntity: Votes = await this.votesService.delete(uid);
|
||||||
|
|
||||||
|
@ -40,6 +40,8 @@ import RolesControllerNotary from "./api/notary/RolesController";
|
|||||||
import OfficeRolesControllerNotary from "./api/notary/OfficeRolesController";
|
import OfficeRolesControllerNotary from "./api/notary/OfficeRolesController";
|
||||||
import FilesControllerCustomer from "./api/customer/FilesController";
|
import FilesControllerCustomer from "./api/customer/FilesController";
|
||||||
import DocumentsControllerCustomer from "./api/customer/DocumentsController";
|
import DocumentsControllerCustomer from "./api/customer/DocumentsController";
|
||||||
|
import OfficeFoldersController from "./api/customer/OfficeFoldersController";
|
||||||
|
import CustomersController from "./api/customer/CustomersController";
|
||||||
import AppointmentsController from "./api/super-admin/AppointmentsController";
|
import AppointmentsController from "./api/super-admin/AppointmentsController";
|
||||||
import VotesController from "./api/super-admin/VotesController";
|
import VotesController from "./api/super-admin/VotesController";
|
||||||
import LiveVoteController from "./api/super-admin/LiveVoteController";
|
import LiveVoteController from "./api/super-admin/LiveVoteController";
|
||||||
@ -95,5 +97,7 @@ export default {
|
|||||||
Container.get(OfficeRolesControllerNotary);
|
Container.get(OfficeRolesControllerNotary);
|
||||||
Container.get(FilesControllerCustomer);
|
Container.get(FilesControllerCustomer);
|
||||||
Container.get(DocumentsControllerCustomer);
|
Container.get(DocumentsControllerCustomer);
|
||||||
|
Container.get(OfficeFoldersController);
|
||||||
|
Container.get(CustomersController)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -6,10 +6,10 @@ export default async function ruleHandler(req: Request, response: Response, next
|
|||||||
const rules = req.body.user.rules;
|
const rules = req.body.user.rules;
|
||||||
const service = req.path && req.path.split("/")[4];
|
const service = req.path && req.path.split("/")[4];
|
||||||
|
|
||||||
if (!rules) {
|
// if (!rules) {
|
||||||
response.status(HttpCodes.UNAUTHORIZED).send("Missing rules in JWT");
|
// response.status(HttpCodes.UNAUTHORIZED).send("Missing rules in JWT");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
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;
|
||||||
|
|
||||||
|
@ -1246,6 +1246,15 @@ export default async function main() {
|
|||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
archived_at: null,
|
||||||
|
name: "Other",
|
||||||
|
office: offices[0],
|
||||||
|
private_description: "Other",
|
||||||
|
public_description: "Other",
|
||||||
|
created_at: new Date(),
|
||||||
|
updated_at: new Date(),
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const officeFolders: OfficeFolder[] = [
|
const officeFolders: OfficeFolder[] = [
|
||||||
|
@ -12,7 +12,7 @@ enum PROVIDER_OPENID {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface ICustomerJwtPayload {
|
interface ICustomerJwtPayload {
|
||||||
customerId: string;
|
userId: string;
|
||||||
email: string;
|
email: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,16 +36,17 @@ export default class AuthService extends BaseService {
|
|||||||
|
|
||||||
public async getCustomerJwtPayload(email:string): Promise<ICustomerJwtPayload | null> {
|
public async getCustomerJwtPayload(email:string): Promise<ICustomerJwtPayload | null> {
|
||||||
const contact = await this.contactService.getByEmail(email);
|
const contact = await this.contactService.getByEmail(email);
|
||||||
|
|
||||||
if (!contact) return null;
|
if (!contact) return null;
|
||||||
|
const customer = await this.customerService.getByUid(contact.customers!.uid, { contact: true });
|
||||||
|
if (!customer) return null;
|
||||||
|
|
||||||
if(contact.customers?.status === ECustomerStatus["PENDING"]) {
|
if(customer.status === ECustomerStatus["PENDING"]) {
|
||||||
contact.customers.status = ECustomerStatus["VALIDATED"];
|
customer.status = ECustomerStatus["VALIDATED"];
|
||||||
this.customerService.update(contact.customers.uid, contact.customers);
|
this.customerService.update(customer.uid, customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
customerId: contact.customers!.uid,
|
userId: customer.uid,
|
||||||
email: contact.email,
|
email: contact.email,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -80,7 +81,6 @@ export default class AuthService extends BaseService {
|
|||||||
rules: rules,
|
rules: rules,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public generateAccessToken(user: any): string {
|
public generateAccessToken(user: any): string {
|
||||||
return jwt.sign({ ...user }, this.variables.ACCESS_TOKEN_SECRET, { expiresIn: "1h" });
|
return jwt.sign({ ...user }, this.variables.ACCESS_TOKEN_SECRET, { expiresIn: "1h" });
|
||||||
}
|
}
|
||||||
|
35
src/services/customer/CustomersService/CustomersService.ts
Normal file
35
src/services/customer/CustomersService/CustomersService.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { Customers, Prisma } from "@prisma/client";
|
||||||
|
import CustomersRepository from "@Repositories/CustomersRepository";
|
||||||
|
import BaseService from "@Services/BaseService";
|
||||||
|
import { Service } from "typedi";
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export default class CustomersService extends BaseService {
|
||||||
|
constructor(private customerRepository: CustomersRepository) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Get all Customers
|
||||||
|
* @throws {Error} If Customers cannot be get
|
||||||
|
*/
|
||||||
|
public async get(query: Prisma.CustomersFindManyArgs): Promise<Customers[]> {
|
||||||
|
return this.customerRepository.findMany(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Get a customer by uid
|
||||||
|
* @throws {Error} If customer cannot be get by uid
|
||||||
|
*/
|
||||||
|
public async getByUid(uid: string, query?: Prisma.CustomersInclude): Promise<Customers | null> {
|
||||||
|
return this.customerRepository.findOneByUid(uid, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Get a customer by contact uid
|
||||||
|
* @throws {Error} If customer cannot be get by contact uid
|
||||||
|
*/
|
||||||
|
public async getByContact(contactUid: string): Promise<Customers | null> {
|
||||||
|
return this.customerRepository.findOneByContact(contactUid);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
import OfficeFoldersRepository from "@Repositories/OfficeFoldersRepository";
|
||||||
|
import BaseService from "@Services/BaseService";
|
||||||
|
import { Service } from "typedi";
|
||||||
|
import { Prisma } from "@prisma/client";
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export default class OfficeFoldersService extends BaseService {
|
||||||
|
constructor(
|
||||||
|
private officeFoldersRepository: OfficeFoldersRepository,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Get all folders
|
||||||
|
* @throws {Error} If folders cannot be get
|
||||||
|
*/
|
||||||
|
public async get(query: Prisma.OfficeFoldersFindManyArgs) {
|
||||||
|
return this.officeFoldersRepository.findMany(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Get a folder by uid
|
||||||
|
* @throws {Error} If folder cannot be get by uid
|
||||||
|
*/
|
||||||
|
public async getByUid(uid: string, query?: Prisma.OfficeFoldersInclude) {
|
||||||
|
return this.officeFoldersRepository.findOneByUid(uid, query);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user