Merge branch 'staging' into preprod
This commit is contained in:
commit
74d5dcb91f
@ -21,8 +21,8 @@ jobs:
|
||||
version: 20.10.12
|
||||
docker_layer_caching: true
|
||||
- run: docker login rg.fr-par.scw.cloud/lecoffre -u nologin -p $SCW_SECRET_KEY
|
||||
- run: docker build --tag rg.fr-par.scw.cloud/lecoffre/back:$TAG .
|
||||
- run: docker push rg.fr-par.scw.cloud/lecoffre/back:$TAG
|
||||
- run: docker build --tag rg.fr-par.scw.cloud/lecoffre/back:${CIRCLE_SHA1:0:7} .
|
||||
- run: docker push rg.fr-par.scw.cloud/lecoffre/back:${CIRCLE_SHA1:0:7}
|
||||
|
||||
|
||||
deploy-docker-image:
|
||||
@ -34,6 +34,10 @@ jobs:
|
||||
- image: cimg/base:stable
|
||||
environment:
|
||||
TAG: << pipeline.git.tag >>
|
||||
parameters:
|
||||
env:
|
||||
type: string
|
||||
default: stg
|
||||
steps:
|
||||
- checkout
|
||||
- kubernetes/install-kubeconfig:
|
||||
@ -43,78 +47,63 @@ jobs:
|
||||
name: Deploy
|
||||
command: >
|
||||
helm upgrade
|
||||
lecoffre-back devops/ -i -f devops/values.yaml
|
||||
-n lecoffre
|
||||
lecoffre-back devops/ -i -f devops/<<parameters.env>>.values.yaml
|
||||
-n lecoffre-<<parameters.env>>
|
||||
--create-namespace
|
||||
--set lecoffreBack.image.repository='rg.fr-par.scw.cloud/lecoffre/back'
|
||||
--set lecoffreBack.image.tag=$TAG
|
||||
--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:
|
||||
version: 2
|
||||
build-and-deploy-stg:
|
||||
build-and-register-stg:
|
||||
jobs:
|
||||
- build-push-docker-image:
|
||||
filters:
|
||||
tags:
|
||||
only: /^v.*/
|
||||
branches:
|
||||
ignore: /.*/
|
||||
context:
|
||||
- staging
|
||||
only: staging
|
||||
- deploy-docker-image:
|
||||
env: stg
|
||||
requires:
|
||||
- build-push-docker-image
|
||||
context:
|
||||
- staging
|
||||
- sc-shared-prd
|
||||
filters:
|
||||
tags:
|
||||
only: /^v.*/
|
||||
branches:
|
||||
ignore: /.*/
|
||||
only: staging
|
||||
|
||||
build-and-deploy-ppd:
|
||||
build-and-register-ppd:
|
||||
jobs:
|
||||
- build-push-docker-image:
|
||||
filters:
|
||||
tags:
|
||||
only: /^v.*/
|
||||
branches:
|
||||
ignore: /.*/
|
||||
context:
|
||||
- production
|
||||
only: preprod
|
||||
- deploy-docker-image:
|
||||
env: ppd
|
||||
requires:
|
||||
- build-push-docker-image
|
||||
context:
|
||||
- production
|
||||
- sc-shared-prd
|
||||
filters:
|
||||
tags:
|
||||
only: /^v.*/
|
||||
branches:
|
||||
ignore: /.*/
|
||||
only: preprod
|
||||
|
||||
|
||||
# build-and-deploy-prod:
|
||||
# jobs:
|
||||
# - build-push-docker-image:
|
||||
# filters:
|
||||
# tags:
|
||||
# only: /^v.*/
|
||||
# branches:
|
||||
# ignore: /.*/
|
||||
# context:
|
||||
# - production
|
||||
# - deploy-docker-image:
|
||||
# requires:
|
||||
# - build-push-docker-image
|
||||
# context:
|
||||
# - production
|
||||
# filters:
|
||||
# tags:
|
||||
# only: /^v.*/
|
||||
# branches:
|
||||
# ignore: /.*/
|
||||
build-and-register-prd:
|
||||
jobs:
|
||||
- build-push-docker-image:
|
||||
filters:
|
||||
branches:
|
||||
only: main
|
||||
- deploy-docker-image:
|
||||
env: prd
|
||||
requires:
|
||||
- build-push-docker-image
|
||||
context:
|
||||
- sc-shared-prd
|
||||
filters:
|
||||
branches:
|
||||
only: main
|
||||
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,6 +6,7 @@ dist
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
package-lock.json
|
||||
|
||||
# envs
|
||||
.env
|
||||
|
@ -42,5 +42,5 @@ COPY --from=builder --chown=lecoffreuser leCoffre/src/common/databases ./src/com
|
||||
|
||||
USER lecoffreuser
|
||||
|
||||
CMD ["npm", "run", "start"]
|
||||
CMD ["npm", "run", "api:start"]
|
||||
EXPOSE 3001
|
46
Dockerfile-Cron
Normal file
46
Dockerfile-Cron
Normal file
@ -0,0 +1,46 @@
|
||||
# Install dependencies only when needed
|
||||
FROM node:19-alpine AS deps
|
||||
|
||||
WORKDIR leCoffre
|
||||
|
||||
RUN npm install -D prisma@4.11.0
|
||||
COPY package.json ./
|
||||
|
||||
RUN apk update && apk add openssh-client git
|
||||
|
||||
COPY id_rsa /root/.ssh/id_rsa
|
||||
RUN chmod 600 ~/.ssh/id_rsa
|
||||
RUN eval "$(ssh-agent -s)" && ssh-add /root/.ssh/id_rsa
|
||||
RUN ssh-keyscan github.com smart-chain-fr/leCoffre-resources.git >> /root/.ssh/known_hosts
|
||||
|
||||
RUN npm install --frozen-lockfile
|
||||
|
||||
# Rebuild the source code only when needed
|
||||
FROM node:19-alpine AS builder
|
||||
|
||||
WORKDIR leCoffre
|
||||
|
||||
COPY --from=deps leCoffre/node_modules ./node_modules
|
||||
COPY --from=deps leCoffre/package.json package.json
|
||||
COPY tsconfig.json tsconfig.json
|
||||
COPY src src
|
||||
|
||||
RUN npx prisma generate
|
||||
RUN npm run build
|
||||
|
||||
# Production image, copy all the files and run next
|
||||
FROM node:19-alpine AS production
|
||||
|
||||
WORKDIR leCoffre
|
||||
|
||||
RUN adduser -D lecoffreuser --uid 10000 && chown -R lecoffreuser .
|
||||
|
||||
COPY --from=builder --chown=lecoffreuser leCoffre/node_modules ./node_modules
|
||||
COPY --from=builder --chown=lecoffreuser leCoffre/dist dist
|
||||
COPY --from=builder --chown=lecoffreuser leCoffre/package.json ./package.json
|
||||
COPY --from=builder --chown=lecoffreuser leCoffre/src/common/databases ./src/common/databases
|
||||
|
||||
USER lecoffreuser
|
||||
|
||||
CMD ["npm", "run", "cron"]
|
||||
EXPOSE 3001
|
@ -21,5 +21,5 @@ version: 0.0.1
|
||||
# incremented each time you make changes to the application. Versions are not expected to
|
||||
# follow Semantic Versioning. They should reflect the version the application is using.
|
||||
# It is recommended to use it with quotes.
|
||||
appVersion: 0.5.6
|
||||
appVersion: 0.5.7
|
||||
|
||||
|
@ -1,24 +1,11 @@
|
||||
dockerPullSecret: secret/data/minteed-ppd/config/dockerpullsecret
|
||||
dockerPullSecret: docker-pull-secret
|
||||
|
||||
namespace: lecoffre
|
||||
scwSecretKey: AgCgjF5QEzxT3GYTS5B6cmQ0e+0/qFWzKaUDSi+Vjc7RoameuvaIJvTXMBkS3he1oy1ulbB34v6vpZI2kxnGNqERA/U5BaYDAyfKSBwMAy4br7HVKhhuwkoF5qoG5JzJXseSmqB1U9vncVIGOZWzJc1Y4/eGlWcvLcLyfw2z/WEpyeNiWJfEhTYpJOB7gv0XnRb2U/JM3jRy1QgEUIk1WR6kgBalF+xaczPQ6uKh+PR2pqkbZa3WaKUrddmzNsgEz4d8PZMWt8IBwR2JOQEHUqCd34p/pJNyLdUgcdDhg02DKwn1oRoAxKTbAio/a7WrMbodjCb3TNWIYGal5mFmItZ7Ok/EBmUf4E85eOkTR+j8ynuuiexld3Q5Kw3o8LsHjgzVL9uP+T2rYaKkjtVt+YQRX1U8l9CrsdUEz0/wEBA0jwCWMfnh1qhD5pM/xwwjsEEAcK4rYV+Q7iAgGZZvZBCQ5aEHzrtn5D95tr1GZCV2hmrW6Seu+LKKLVBS1JmsuEsOuhudYsEK9m2RYVcxbjuS5eokKEjNrGobf2oB8rhBByavfw1JTBixR5JrI8lcYlnCa+oEhxXKJY+4Fx5SAB4YaLCMSo5vw6zsFQ3WKQzlEmCFt+EnapS+a+MGrdlwq07OHTDpvgk/1z39hopoCuhhKckGGfErLXsTYQvDOkFu+EPzgY7m7qDw/d9pSiht5tuSOkAqeOgm7tpNkUufZhaXmP+1aT7i+H5gq1JILGAmXzTI5Wc=
|
||||
|
||||
lecoffreBack:
|
||||
serviceAccountName: lecoffre-back-sa
|
||||
command: "'sh', '-c', '. /vault/secrets/envs-api && npm run api:start'"
|
||||
vault:
|
||||
role : custom_lecoffre-back_injector_rol
|
||||
server: https://vault-ppd.smart-chain.fr
|
||||
annotations:
|
||||
vault.hashicorp.com/agent-pre-populate-only: "true"
|
||||
vault.hashicorp.com/agent-inject: "true"
|
||||
vault.hashicorp.com/agent-inject-secret-envs-api: secret/data/lecoffre-back-ppd/config/envs-api
|
||||
vault.hashicorp.com/role: custom_lecoffre-back_injector_rol
|
||||
vault.hashicorp.com/agent-inject-template-envs-api: |
|
||||
{{ with secret "secret/data/lecoffre-back-ppd/config/envs-api" }}
|
||||
{{ range $k, $v := .Data.data }}
|
||||
export {{ $k }}="{{ $v }}"
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
command: "'sh', '-c', 'export $(xargs </etc/env/.env) && npm run api:start'"
|
||||
envSecrets: ppd-env
|
||||
imagePullSecrets:
|
||||
- name: docker-pull-secret
|
||||
image:
|
||||
@ -31,14 +18,37 @@ lecoffreBack:
|
||||
limits:
|
||||
memory: 2Gi
|
||||
ingress:
|
||||
host: api.ppd.lecoffre.smart-chain.fr
|
||||
host: api.stg.lecoffre.smart-chain.fr
|
||||
tls:
|
||||
hosts:
|
||||
- api.ppd.lecoffre.smart-chain.fr
|
||||
- api.stg.lecoffre.smart-chain.fr
|
||||
secretName: api-tls
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: nginx
|
||||
cert-manager.io/cluster-issuer: letsencrypt-prod
|
||||
nginx.ingress.kubernetes.io/from-to-www-redirect: "true"
|
||||
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
|
||||
env:
|
||||
- key: .env
|
||||
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"
|
||||
|
||||
|
54
devops/prd.values.yaml
Normal file
54
devops/prd.values.yaml
Normal file
@ -0,0 +1,54 @@
|
||||
dockerPullSecret: docker-pull-secret
|
||||
|
||||
scwSecretKey: AgBG2y7uQuap+2akNPGFxpCR+l0INO6Wxez5qljtY6t71GFGhJLYN9ZfefflKcFzD2Nv7DQMXXhpnCCaFti+9JMCMDuN324dDgtMMLTot+Pkxk/bAm+L8t3HfRharFdLz/vvzg77bvypi28TEoNYR/AM0e8VMYxBEgEp2TmP5uXcxZOgPzXMrfQoSdNRyzGTJ5tXZwe3PP7XvXyTNsZzHBtoQQM+nul9nL+VFA7CBRaaOpCmKOXjAlt7TyNXo4X5eYBNlxr+NuQw4dh4E/1zqdU/dDCE1+vx88BDbdydBA1qJaTOUSGTFquSK4kb9qAVAexBAIUqRwpfEW6Li945AXtnxLN42gEGPRsA9tSXL2c20k6thuRCqxwEOZljq2E03qtLAkxdP6WFBcb77o4PIEMZ8AmzPASnI+eW5z2mCoP3L+HZQrTLliDjmF4AMtOfZxRi0CCTrsSabOrimJC6v3y3ve0VcSsjA3rd5vvJ3Va4mZK4JAtYwEUx4PCHCGkUxc0w6jRwKB5tL/auZVT4SV/0z/WgW4Kq4AdvxsU6yGOqflt6e3ePIIuvCgjw+1yOYRpUiSGj36oOqNPMA4smxIB7p7Gi3csqt2TrQoW3TaLv/s7gbCcxHWSor+WT71WGg8AVmLm+FzUINmNop+c2RNo3O/Gj7h1uybX/pj+tRLNOuBQCqa+GQkY2bT2NcT9ifnAZB6K+2zAWXl+tdbMlDGV89P2yMYuRMdHGhuOoyuIUPWeA5i0=
|
||||
|
||||
lecoffreBack:
|
||||
serviceAccountName: lecoffre-back-sa
|
||||
command: "'sh', '-c', 'export $(xargs </etc/env/.env) && npm run api:start'"
|
||||
envSecrets: prd-env
|
||||
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
|
||||
ingress:
|
||||
host: api.stg.lecoffre.smart-chain.fr
|
||||
tls:
|
||||
hosts:
|
||||
- api.stg.lecoffre.smart-chain.fr
|
||||
secretName: api-tls
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: nginx
|
||||
cert-manager.io/cluster-issuer: letsencrypt-prod
|
||||
nginx.ingress.kubernetes.io/from-to-www-redirect: "true"
|
||||
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
|
||||
env:
|
||||
- key: .env
|
||||
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"
|
||||
|
@ -1,24 +1,11 @@
|
||||
dockerPullSecret: secret/data/minteed-stg/config/dockerpullsecret
|
||||
dockerPullSecret: id:47c1c301-1f02-49cc-9e5c-c1225a770aa8
|
||||
|
||||
namespace: lecoffre
|
||||
scwSecretKey: AgChoEnPitXp4Ny/rVMEcevaWKNVpyj2cJYAcq+yFqKwVwnLB+ffDvwqz9XBHu+6d4Nyyjkf37zUAMoaM21lEDWA7x3zfG2/D/j+rvX1qxzZgLD0mjBk7fGElVm332I6JA83oInes8AMMYEDPLElzHnpKRb9KtkIP4NzgOcCeW0ijft3N7Vroez6LEHsBPCA1I9XjKSkGEDvrO0MhWX3iJOlfz+SPMfJAV7rPawOs0ZmohTHrPW8qIvGDn8HCzKyU8zRBoMt+Ogpf5pH4U3JryEFuqD61KAQgablAM8edPIvsgNno9HAEuC2QtRLYA9aUhuKdaKuS58c9P2E80PHWXIlbpFCg6EugQTgNfnYp+3qDUNz8edeCfapYLvF4s9eCMGyMsGnpDR8EDNOyuGy7Y3l7okX8Xqu464gMp9E+hX7bHkcD6a4xfyIgJcWxsku0tm1TH1dpn4M1UXRuyZZif8P08nuE6MTUL67sAR9J1lpn4lVEL4kflk0pP2tZ5ncgPQFafJrRz05krMb0eU5tb2H4gs7ao/LL6idWo8MM9K1yr8lIuT5x2WW5CX+RjA+i50ex114V6vX3PNP5oVyt+DynTUB9QmXzVm3oLfDc3Cae1uqh7X0CFd+xiztJBtg0VtJaD/xUJcuWfY4cV2lERo9fRrykltzlJqiXHO4nowt8OtN0BcViVV8NJhPhYFzyb4ympxpOlTjm3GETuT2TYhUqdgS9nzleEAbOmOHZdIO2COunPE=
|
||||
|
||||
lecoffreBack:
|
||||
serviceAccountName: lecoffre-back-sa
|
||||
command: "'sh', '-c', '. /vault/secrets/envs-api && npm run api:start'"
|
||||
vault:
|
||||
role : custom_lecoffre-back_injector_rol
|
||||
server: https://vault-stg.smart-chain.fr
|
||||
annotations:
|
||||
vault.hashicorp.com/agent-pre-populate-only: "true"
|
||||
vault.hashicorp.com/agent-inject: "true"
|
||||
vault.hashicorp.com/agent-inject-secret-envs-api: secret/data/lecoffre-back-stg/config/envs-api
|
||||
vault.hashicorp.com/role: custom_lecoffre-back_injector_rol
|
||||
vault.hashicorp.com/agent-inject-template-envs-api: |
|
||||
{{ with secret "secret/data/lecoffre-back-stg/config/envs-api" }}
|
||||
{{ range $k, $v := .Data.data }}
|
||||
export {{ $k }}="{{ $v }}"
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
envSecrets: stg-env
|
||||
command: "'sh', '-c', 'export $(xargs </etc/env/.env) && npm run api:start'"
|
||||
imagePullSecrets:
|
||||
- name: docker-pull-secret
|
||||
image:
|
||||
@ -41,4 +28,29 @@ lecoffreBack:
|
||||
cert-manager.io/cluster-issuer: letsencrypt-prod
|
||||
nginx.ingress.kubernetes.io/from-to-www-redirect: "true"
|
||||
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
|
||||
# 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"
|
||||
|
||||
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,8 +5,8 @@ metadata:
|
||||
spec:
|
||||
refreshInterval: 1h
|
||||
secretStoreRef:
|
||||
name: dockerpullsecret-vault-cluster-secret-store
|
||||
kind: ClusterSecretStore
|
||||
name: secret-store
|
||||
kind: SecretStore
|
||||
target:
|
||||
template:
|
||||
type: kubernetes.io/dockerconfigjson
|
||||
@ -16,4 +16,4 @@ spec:
|
||||
- secretKey: .dockerconfigjson
|
||||
remoteRef:
|
||||
key: {{ .Values.dockerPullSecret }}
|
||||
property: .dockerconfigjson
|
||||
version: latest_enabled
|
||||
|
@ -3,7 +3,6 @@ apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: lecoffre-back
|
||||
namespace: {{ .Values.namespace }}
|
||||
{{if .Values.lecoffreBack.ingress.annotations}}
|
||||
annotations:
|
||||
{{toYaml .Values.lecoffreBack.ingress.annotations | indent 4 }}
|
||||
@ -28,7 +27,6 @@ apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: lecoffre-back-svc
|
||||
namespace: {{ .Values.namespace }}
|
||||
labels:
|
||||
spec:
|
||||
ports:
|
||||
@ -42,7 +40,6 @@ apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: lecoffre-back
|
||||
namespace: {{ .Values.namespace }}
|
||||
labels:
|
||||
app: lecoffre-back
|
||||
spec:
|
||||
@ -53,7 +50,6 @@ spec:
|
||||
template:
|
||||
metadata:
|
||||
annotations:
|
||||
{{toYaml .Values.lecoffreBack.vault.annotations | indent 8 }}
|
||||
labels:
|
||||
app: lecoffre-back
|
||||
spec:
|
||||
@ -62,10 +58,17 @@ spec:
|
||||
- name: docker-pull-secret
|
||||
containers:
|
||||
- name: lecoffre-back
|
||||
image: "{{ .Values.lecoffreBack.image.repository }}:v{{ .Chart.AppVersion }}"
|
||||
image: "{{ .Values.lecoffreBack.image.repository }}:{{ .Values.lecoffreBack.image.tag }}"
|
||||
{{if .Values.lecoffreBack.resources}}
|
||||
resources:
|
||||
{{toYaml .Values.lecoffreBack.resources | indent 10}}
|
||||
{{end}}
|
||||
imagePullPolicy: {{ .Values.lecoffreBack.image.pullPolicy }}
|
||||
command: [{{ .Values.lecoffreBack.command }}]
|
||||
volumeMounts:
|
||||
- name: secret-volume
|
||||
mountPath: /etc/env
|
||||
volumes:
|
||||
- name: secret-volume
|
||||
secret:
|
||||
secretName: {{ .Values.lecoffreBack.envSecrets }}
|
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
devops/templates/sealed-secret.yaml
Normal file
12
devops/templates/sealed-secret.yaml
Normal file
@ -0,0 +1,12 @@
|
||||
apiVersion: bitnami.com/v1alpha1
|
||||
kind: SealedSecret
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
name: scw-secret-key
|
||||
spec:
|
||||
encryptedData:
|
||||
SCW_SECRET_KEY: {{ .Values.scwSecretKey }}
|
||||
template:
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
name: scw-secret-key
|
15
devops/templates/secret-store.yaml
Normal file
15
devops/templates/secret-store.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
apiVersion: external-secrets.io/v1beta1
|
||||
kind: SecretStore
|
||||
metadata:
|
||||
name: secret-store
|
||||
spec:
|
||||
provider:
|
||||
scaleway:
|
||||
region: fr-par
|
||||
projectId: c0ed1e9e-d945-461f-920c-98c844ef1ad4
|
||||
accessKey:
|
||||
value: SCWNCSH22EMVGT3MNX09
|
||||
secretKey:
|
||||
secretRef:
|
||||
name: scw-secret-key
|
||||
key: SCW_SECRET_KEY
|
16
devops/templates/secrets.yaml
Normal file
16
devops/templates/secrets.yaml
Normal file
@ -0,0 +1,16 @@
|
||||
apiVersion: external-secrets.io/v1beta1
|
||||
kind: ExternalSecret
|
||||
metadata:
|
||||
name: {{ .Values.lecoffreBack.envSecrets }}
|
||||
spec:
|
||||
refreshInterval: 1h
|
||||
secretStoreRef:
|
||||
kind: SecretStore
|
||||
name: secret-store
|
||||
data:
|
||||
{{ range $v := .Values.lecoffreBack.env }}
|
||||
- secretKey: {{ $v.key }}
|
||||
remoteRef:
|
||||
key: {{ $v.scwID}}
|
||||
version: latest_enabled
|
||||
{{ end }}
|
@ -12,3 +12,19 @@ metadata:
|
||||
annotations:
|
||||
kubernetes.io/service-account.name: {{ .Values.lecoffreBack.serviceAccountName }}
|
||||
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
|
@ -1,29 +1,17 @@
|
||||
dockerPullSecret: secret/data/minteed-stg/config/dockerpullsecret
|
||||
dockerPullSecret: docker-pull-secret
|
||||
|
||||
namespace: lecoffre
|
||||
scwSecretKey: ss
|
||||
|
||||
lecoffreBack:
|
||||
serviceAccountName: lecoffre-back-sa
|
||||
command: "'sh', '-c', '. /vault/secrets/envs-api && npm run api:start'"
|
||||
vault:
|
||||
role : custom_lecoffre-back_injector_rol
|
||||
server: https://vault-stg.smart-chain.fr
|
||||
annotations:
|
||||
vault.hashicorp.com/agent-pre-populate-only: "true"
|
||||
vault.hashicorp.com/agent-inject: "true"
|
||||
vault.hashicorp.com/agent-inject-secret-envs-api: secret/data/lecoffre-back-stg/config/envs-api
|
||||
vault.hashicorp.com/role: custom_lecoffre-back_injector_rol
|
||||
vault.hashicorp.com/agent-inject-template-envs-api: |
|
||||
{{ with secret "secret/data/lecoffre-back-stg/config/envs-api" }}
|
||||
{{ range $k, $v := .Data.data }}
|
||||
export {{ $k }}="{{ $v }}"
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
command: "npm run api:start"
|
||||
envSecrets: env-env
|
||||
imagePullSecrets:
|
||||
- name: docker-pull-secret
|
||||
image:
|
||||
pullPolicy: Always
|
||||
repository: "rg.fr-par.scw.cloud/lecoffre/back"
|
||||
tag:
|
||||
resources:
|
||||
requests:
|
||||
cpu: 200m
|
||||
@ -42,3 +30,7 @@ lecoffreBack:
|
||||
nginx.ingress.kubernetes.io/from-to-www-redirect: "true"
|
||||
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
|
||||
|
||||
env:
|
||||
- key: a
|
||||
scwID: b
|
||||
|
||||
|
1558
package-lock.json
generated
1558
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
15
package.json
15
package.json
@ -20,6 +20,7 @@
|
||||
"build-db": "npx prisma migrate dev",
|
||||
"build": "tsc",
|
||||
"start": "node ./dist/entries/App.js",
|
||||
"cron": "node ./dist/entries/Cron.js",
|
||||
"api:start": "npm run migrate && npm run start",
|
||||
"dev": "nodemon -V",
|
||||
"format": "prettier --write src",
|
||||
@ -27,7 +28,8 @@
|
||||
"migrate": "npx prisma migrate deploy",
|
||||
"docker:up:test": "docker-compose -f docker-compose-test.yml up -d",
|
||||
"docker:down:test": "docker-compose down",
|
||||
"test": "tsc && npm run docker:up:test && npm run migrate:test && dotenv -e .env.test -- jest -i --verbose ./dist/test/* && npm run docker:down:test"
|
||||
"test": "tsc && npm run docker:up:test && npm run migrate:test && dotenv -e .env.test -- jest -i --verbose ./dist/test/* && npm run docker:down:test",
|
||||
"seed": "ts-node src/common/databases/seeders/seeder.ts"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -40,19 +42,22 @@
|
||||
},
|
||||
"homepage": "https://github.com/smart-chain-fr/leCoffre-back#readme",
|
||||
"dependencies": {
|
||||
"@mailchimp/mailchimp_transactional": "^1.0.50",
|
||||
"@pinata/sdk": "^2.1.0",
|
||||
"@prisma/client": "^4.11.0",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.14.0",
|
||||
"classnames": "^2.3.2",
|
||||
"cors": "^2.8.5",
|
||||
"cron": "^2.3.1",
|
||||
"express": "^4.18.2",
|
||||
"jsonwebtoken": "^9.0.0",
|
||||
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.47",
|
||||
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.69",
|
||||
"module-alias": "^2.2.2",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"next": "^13.1.5",
|
||||
"node-cache": "^5.1.2",
|
||||
"node-fetch": "^2.6.11",
|
||||
"node-schedule": "^2.1.1",
|
||||
"prisma-query": "^2.0.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
@ -65,11 +70,15 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/cors": "^2.8.13",
|
||||
"@types/cron": "^2.0.1",
|
||||
"@types/express": "^4.17.16",
|
||||
"@types/jest": "^29.5.0",
|
||||
"@types/jsonwebtoken": "^9.0.1",
|
||||
"@types/mailchimp__mailchimp_transactional": "^1.0.5",
|
||||
"@types/module-alias": "^2.0.1",
|
||||
"@types/multer": "^1.4.7",
|
||||
"@types/node": "^18.11.18",
|
||||
"@types/node-fetch": "^2.6.3",
|
||||
"@types/node-schedule": "^2.1.0",
|
||||
"@types/uuid": "^9.0.0",
|
||||
"dotenv": "^16.0.3",
|
||||
@ -81,6 +90,6 @@
|
||||
},
|
||||
"prisma": {
|
||||
"schema": "src/common/databases/schema.prisma",
|
||||
"seed": "ts-node src/common/databases/seeders/seeder2.ts"
|
||||
"seed": "ts-node src/common/databases/seeders/seeder.ts"
|
||||
}
|
||||
}
|
||||
|
146
src/app/api/admin/CustomersController.ts
Normal file
146
src/app/api/admin/CustomersController.ts
Normal file
@ -0,0 +1,146 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import CustomersService from "@Services/admin/CustomersService/CustomersService";
|
||||
import { Service } from "typedi";
|
||||
import { Customer } from "le-coffre-resources/dist/Admin";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class CustomersController extends ApiController {
|
||||
constructor(private customersService: CustomersService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all customers
|
||||
*/
|
||||
@Get("/api/v1/admin/customers", [authHandler, roleHandler, ruleHandler])
|
||||
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 Create a new customer
|
||||
*/
|
||||
@Post("/api/v1/admin/customers", [authHandler, ruleHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init IUser resource with request body values
|
||||
const customerEntity = Customer.hydrate<Customer>(req.body);
|
||||
//validate user
|
||||
await validateOrReject(customerEntity, { groups: ["createCustomer"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const customerEntityCreated = await this.customersService.create(customerEntity);
|
||||
//Hydrate ressource with prisma entity
|
||||
const customer = Customer.hydrate<Customer>(customerEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpCreated(response, customer);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific customer by uid
|
||||
*/
|
||||
@Put("/api/v1/admin/customers/:uid", [authHandler, roleHandler, ruleHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const userFound = await this.customersService.getByUid(uid);
|
||||
|
||||
if (!userFound) {
|
||||
this.httpNotFoundRequest(response, "user not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init IUser resource with request body values
|
||||
const customerEntity = Customer.hydrate<Customer>(req.body);
|
||||
|
||||
//validate user
|
||||
await validateOrReject(customerEntity, { groups: ["updateCustomer"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const customerEntityUpdated = await this.customersService.update(uid, customerEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const customer = Customer.hydrate<Customer>(customerEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, customer);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific customer by uid
|
||||
*/
|
||||
@Get("/api/v1/admin/customers/:uid", [authHandler, roleHandler, ruleHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
//get query
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
176
src/app/api/admin/DeedTypesController.ts
Normal file
176
src/app/api/admin/DeedTypesController.ts
Normal file
@ -0,0 +1,176 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import DeedTypesService from "@Services/admin/DeedTypesService/DeedTypesService";
|
||||
import { DeedTypes, Prisma } from "@prisma/client";
|
||||
import { DeedType } from "le-coffre-resources/dist/Admin";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import deedTypeHandler from "@App/middlewares/OfficeMembershipHandlers/DeedTypeHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class DeedTypesController extends ApiController {
|
||||
constructor(private deedTypesService: DeedTypesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all deedtypes
|
||||
* @returns Deedtype[] list of deedtypes
|
||||
*/
|
||||
@Get("/api/v1/admin/deed-types", [authHandler, roleHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query: Prisma.DeedTypesFindManyArgs = {};
|
||||
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: {
|
||||
name: {
|
||||
contains: filter,
|
||||
mode: "insensitive",
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
if(!query.where) query.where = { office: officeWhereInput};
|
||||
query.where.office = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const deedTypeEntities: DeedTypes[] = await this.deedTypesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const DeedTypes = DeedType.hydrateArray<DeedType>(deedTypeEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, DeedTypes);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new deedtype
|
||||
* @returns Deedtype created
|
||||
*/
|
||||
@Post("/api/v1/admin/deed-types", [authHandler, roleHandler, ruleHandler, deedTypeHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init DeedType resource with request body values
|
||||
const deedTypeEntity = DeedType.hydrate<DeedType>(req.body);
|
||||
|
||||
//validate deed type
|
||||
await validateOrReject(deedTypeEntity, { groups: ["createDeedType"], forbidUnknownValues: false });
|
||||
const doesExist = await this.deedTypesService.get({ where: { name: deedTypeEntity.name } });
|
||||
if (doesExist.length > 0) {
|
||||
this.httpBadRequest(response, "Deed type name already used");
|
||||
return;
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const deedTypeEntityCreated = await this.deedTypesService.create(deedTypeEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deedType = DeedType.hydrate<DeedType>(deedTypeEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpCreated(response, deedType);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific deedtype by uid
|
||||
* @returns Deedtype modified
|
||||
*/
|
||||
@Put("/api/v1/admin/deed-types/:uid", [authHandler, roleHandler, ruleHandler, deedTypeHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const deedTypeFound = await this.deedTypesService.getByUid(uid);
|
||||
|
||||
if (!deedTypeFound) {
|
||||
this.httpNotFoundRequest(response, "deed type not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init DeedType resource with request body values
|
||||
const deedTypeEntity = DeedType.hydrate<DeedType>(req.body);
|
||||
|
||||
//validate deed type
|
||||
await validateOrReject(deedTypeEntity, { groups: ["updateDeedType"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const deedTypeEntityUpdated = await this.deedTypesService.update(uid, deedTypeEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deedType = DeedType.hydrate<DeedType>(deedTypeEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deedType);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific deedtype by uid
|
||||
* @returns IDeedtype
|
||||
*/
|
||||
@Get("/api/v1/admin/deed-types/:uid", [authHandler, roleHandler, ruleHandler, deedTypeHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const deedTypeEntity = await this.deedTypesService.getByUid(uid, query);
|
||||
|
||||
if (!deedTypeEntity) {
|
||||
this.httpNotFoundRequest(response, "deed type not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deedType = DeedType.hydrate<DeedType>(deedTypeEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deedType);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
128
src/app/api/admin/DeedsController.ts
Normal file
128
src/app/api/admin/DeedsController.ts
Normal file
@ -0,0 +1,128 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import DeedsService from "@Services/admin/DeedsService/DeedsService";
|
||||
import { Service } from "typedi";
|
||||
import { Deeds, Prisma } from "@prisma/client";
|
||||
import { Deed } from "le-coffre-resources/dist/Admin";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import deedHandler from "@App/middlewares/OfficeMembershipHandlers/DeedHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class DeedsController extends ApiController {
|
||||
constructor(private deedsService: DeedsService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all deeds
|
||||
* @returns Deed[] list of deeds
|
||||
*/
|
||||
@Get("/api/v1/admin/deeds", [authHandler, roleHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query: Prisma.DeedsFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
if(!query.where) query.where = { deed_type : {office: officeWhereInput}};
|
||||
query.where.deed_type!.office = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const deedEntities: Deeds[] = await this.deedsService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deeds = Deed.hydrateArray<Deed>(deedEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deeds);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific deed by uid
|
||||
* @returns Deed
|
||||
*/
|
||||
@Get("/api/v1/admin/deeds/:uid", [authHandler, roleHandler, ruleHandler, deedHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const deedEntity = await this.deedsService.getByUid(uid, query);
|
||||
|
||||
if (!deedEntity) {
|
||||
this.httpNotFoundRequest(response, "deed not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deed = Deed.hydrate<Deed>(deedEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deed);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific deed by uid
|
||||
*/
|
||||
@Put("/api/v1/admin/deeds/:uid", [authHandler, roleHandler, ruleHandler, deedHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const deedFound = await this.deedsService.getByUid(uid);
|
||||
|
||||
if (!deedFound) {
|
||||
this.httpNotFoundRequest(response, "deed not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init OfficeFolder resource with request body values
|
||||
const deedEntity = Deed.hydrate<Deed>(req.body);
|
||||
|
||||
//validate folder
|
||||
await validateOrReject(deedEntity, { groups: ["updateDeed"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const deedEntityUpdated = await this.deedsService.update(uid, deedEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deed = Deed.hydrate<Deed>(deedEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deed);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
147
src/app/api/admin/DocumentTypesController.ts
Normal file
147
src/app/api/admin/DocumentTypesController.ts
Normal file
@ -0,0 +1,147 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import DocumentTypesService from "@Services/admin/DocumentTypesService/DocumentTypesService";
|
||||
import { DocumentTypes, Prisma } from "@prisma/client";
|
||||
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
||||
import { DocumentType } from "le-coffre-resources/dist/Admin";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import documentTypeHandler from "@App/middlewares/OfficeMembershipHandlers/DocumentTypeHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class DocumentTypesController extends ApiController {
|
||||
constructor(private documentTypesService: DocumentTypesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all document-types
|
||||
*/
|
||||
@Get("/api/v1/admin/document-types", [authHandler, roleHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query: Prisma.DocumentTypesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
if(!query.where) query.where = { office: officeWhereInput};
|
||||
query.where.office = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentTypeEntities: DocumentTypes[] = await this.documentTypesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documentTypes = DocumentType.hydrateArray<DocumentType>(documentTypeEntities, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documentTypes);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new documentType
|
||||
*/
|
||||
@Post("/api/v1/admin/document-types", [authHandler, roleHandler, ruleHandler, documentTypeHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init DocumentType resource with request body values
|
||||
const documentTypeEntity = DocumentType.hydrate<DocumentType>(req.body);
|
||||
//validate user
|
||||
await validateOrReject(documentTypeEntity, { groups: ["createDocumentType"], forbidUnknownValues: false });
|
||||
//call service to get prisma entity
|
||||
const documentTypeEntityCreated = await this.documentTypesService.create(documentTypeEntity);
|
||||
//Hydrate ressource with prisma entity
|
||||
const userEntityCreated = DocumentType.hydrate<DocumentType>(documentTypeEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
//success
|
||||
this.httpCreated(response, userEntityCreated);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific documentType by uid
|
||||
*/
|
||||
@Put("/api/v1/admin/document-types/:uid", [authHandler, roleHandler, ruleHandler, documentTypeHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const documentTypeFound = await this.documentTypesService.getByUid(uid);
|
||||
|
||||
if (!documentTypeFound) {
|
||||
this.httpNotFoundRequest(response, "document type not found");
|
||||
return;
|
||||
}
|
||||
//init DocumentType resource with request body values
|
||||
const documentTypeEntity = DocumentType.hydrate<DocumentType>(req.body);
|
||||
|
||||
//validate user
|
||||
await validateOrReject(documentTypeEntity, { groups: ["updateDocumentType"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentTypeEntityUpdated = await this.documentTypesService.update(uid, documentTypeEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documentType = DocumentType.hydrate<DocumentType>(documentTypeEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documentType);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific documentType by uid
|
||||
*/
|
||||
@Get("/api/v1/admin/document-types/:uid", [authHandler, ruleHandler, documentTypeHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const documentTypeEntity = await this.documentTypesService.getByUid(uid, query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const user = ObjectHydrate.hydrate<DocumentType>(new DocumentType(), documentTypeEntity!, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, user);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
187
src/app/api/admin/DocumentsController.ts
Normal file
187
src/app/api/admin/DocumentsController.ts
Normal file
@ -0,0 +1,187 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import DocumentsService from "@Services/admin/DocumentsService/DocumentsService";
|
||||
import { Documents, Prisma } from "@prisma/client";
|
||||
import { Document } from "le-coffre-resources/dist/Admin";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import documentHandler from "@App/middlewares/OfficeMembershipHandlers/DocumentHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class DocumentsController extends ApiController {
|
||||
constructor(private documentsService: DocumentsService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all documents
|
||||
* @returns IDocument[] list of documents
|
||||
*/
|
||||
@Get("/api/v1/admin/documents", [authHandler, roleHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query: Prisma.DocumentsFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
if(!query.where) query.where = { document_type : {office: officeWhereInput}};
|
||||
query.where.document_type!.office = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntities = await this.documentsService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documents = Document.hydrateArray<Document>(documentEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documents);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new document
|
||||
* @returns IDocument created
|
||||
*/
|
||||
@Post("/api/v1/admin/documents", [authHandler, roleHandler, ruleHandler, documentHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init Document resource with request body values
|
||||
const documentEntity = Document.hydrate<Document>(req.body);
|
||||
|
||||
//validate document
|
||||
await validateOrReject(documentEntity, { groups: ["createDocument"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntityCreated = await this.documentsService.create(documentEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(documentEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpCreated(response, document);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Update a specific document
|
||||
*/
|
||||
@Put("/api/v1/admin/documents/:uid", [authHandler, roleHandler, ruleHandler, documentHandler])
|
||||
protected async update(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const documentFound = await this.documentsService.getByUid(uid);
|
||||
|
||||
if (!documentFound) {
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init Document resource with request body values
|
||||
const documentEntity = Document.hydrate<Document>(req.body);
|
||||
|
||||
//validate document
|
||||
await validateOrReject(documentEntity, { groups: ["updateDocument"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity, req.body.refused_reason);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(documentEntityUpdated, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a specific document
|
||||
*/
|
||||
@Delete("/api/v1/admin/documents/:uid", [authHandler, roleHandler, ruleHandler, documentHandler])
|
||||
protected async delete(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const documentFound = await this.documentsService.getByUid(uid);
|
||||
|
||||
if (!documentFound) {
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntity: Documents = await this.documentsService.delete(uid);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific document by uid
|
||||
*/
|
||||
@Get("/api/v1/admin/documents/:uid", [authHandler, roleHandler, ruleHandler, documentHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const documentEntity = await this.documentsService.getByUid(uid, query);
|
||||
|
||||
if (!documentEntity) {
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
150
src/app/api/admin/FilesController.ts
Normal file
150
src/app/api/admin/FilesController.ts
Normal file
@ -0,0 +1,150 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import FilesService from "@Services/common/FilesService/FilesService";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { File } from "le-coffre-resources/dist/Admin";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import fileHandler from "@App/middlewares/OfficeMembershipHandlers/FileHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class FilesController extends ApiController {
|
||||
constructor(private filesService: FilesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all Files
|
||||
* @returns File[] list of Files
|
||||
*/
|
||||
@Get("/api/v1/admin/files", [authHandler, roleHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query: Prisma.FilesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
if(!query.where) query.where = { document: { folder: {office: officeWhereInput}}};
|
||||
query.where.document!.folder!.office = officeWhereInput;
|
||||
//call service to get prisma entity
|
||||
const fileEntities = await this.filesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const files = File.hydrateArray<File>(fileEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, files);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific File by uid
|
||||
*/
|
||||
@Get("/api/v1/admin/files/download/:uid", [authHandler, roleHandler, ruleHandler, fileHandler])
|
||||
protected async download(req: Request, response: Response) {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "uid not found");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const fileInfo = await this.filesService.download(uid);
|
||||
|
||||
if (!fileInfo) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
response.setHeader("Content-Type", fileInfo.file.mimetype);
|
||||
response.setHeader("Content-Disposition", `inline; filename=${encodeURIComponent(fileInfo.file.file_name)}`);
|
||||
|
||||
this.httpSuccess(response, fileInfo.buffer);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a specific File
|
||||
*/
|
||||
@Delete("/api/v1/admin/files/:uid", [authHandler, roleHandler, ruleHandler, fileHandler])
|
||||
protected async delete(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const fileFound = await this.filesService.getByUid(uid);
|
||||
|
||||
if (!fileFound) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const fileEntity = await this.filesService.deleteKeyAndArchive(uid);
|
||||
|
||||
if (!fileEntity) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const file = File.hydrate<File>(fileEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, file);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific File by uid
|
||||
*/
|
||||
@Get("/api/v1/admin/files/:uid", [authHandler, roleHandler, ruleHandler, fileHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const fileEntity = await this.filesService.getByUid(uid, query);
|
||||
|
||||
if (!fileEntity) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const file = File.hydrate<File>(fileEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, file);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
215
src/app/api/admin/OfficeFoldersController.ts
Normal file
215
src/app/api/admin/OfficeFoldersController.ts
Normal file
@ -0,0 +1,215 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import OfficeFoldersService from "@Services/admin/OfficeFoldersService/OfficeFoldersService";
|
||||
import { Service } from "typedi";
|
||||
import { OfficeFolders, Prisma } from "@prisma/client";
|
||||
import { OfficeFolder } from "le-coffre-resources/dist/Admin";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import folderHandler from "@App/middlewares/OfficeMembershipHandlers/FolderHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class OfficeFoldersController extends ApiController {
|
||||
constructor(private officeFoldersService: OfficeFoldersService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all folders
|
||||
*/
|
||||
@Get("/api/v1/admin/folders", [authHandler, roleHandler, ruleHandler])
|
||||
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 officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
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 Create a new folder
|
||||
*/
|
||||
@Post("/api/v1/admin/folders", [authHandler, roleHandler, ruleHandler, folderHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init OfficeFolder resource with request body values
|
||||
const officeFolderRessource = OfficeFolder.hydrate<OfficeFolder>(req.body);
|
||||
await officeFolderRessource.validateOrReject?.({ groups: ["createFolder"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeFolderEntity = await this.officeFoldersService.create(officeFolderRessource);
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolders = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntity, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
//success
|
||||
this.httpCreated(response, officeFolders);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific folder by uid
|
||||
*/
|
||||
@Put("/api/v1/admin/folders/:uid", [authHandler, roleHandler, ruleHandler, folderHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const officeFolderFound = await this.officeFoldersService.getByUid(uid);
|
||||
|
||||
if (!officeFolderFound) {
|
||||
this.httpNotFoundRequest(response, "office folder not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init OfficeFolder resource with request body values
|
||||
const officeFolderEntity = OfficeFolder.hydrate<OfficeFolder>(req.body);
|
||||
|
||||
//validate folder
|
||||
await validateOrReject(officeFolderEntity, { groups: ["updateFolder"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeFolderEntityUpdated = await this.officeFoldersService.update(uid, officeFolderEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolders = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntityUpdated, {
|
||||
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/admin/folders/:uid", [authHandler, roleHandler, ruleHandler, folderHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
//get query
|
||||
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;
|
||||
}
|
||||
this.httpSuccess(response, await this.officeFoldersService.getByUid("uid"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a specific folder
|
||||
*/
|
||||
@Delete("/api/v1/admin/folders/:uid", [authHandler, roleHandler, ruleHandler, folderHandler])
|
||||
protected async delete(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const officeFolderFound = await this.officeFoldersService.getByUid(uid);
|
||||
|
||||
if (!officeFolderFound) {
|
||||
this.httpNotFoundRequest(response, "office folder not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeFoldertEntity: OfficeFolders = await this.officeFoldersService.delete(uid);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFoldertEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeFolder);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
167
src/app/api/admin/OfficeRolesController.ts
Normal file
167
src/app/api/admin/OfficeRolesController.ts
Normal file
@ -0,0 +1,167 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import OfficeRolesService from "@Services/admin/OfficeRolesService/OfficeRolesService";
|
||||
import { Service } from "typedi";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import { OfficeRole } from "le-coffre-resources/dist/Admin";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import officeRoleHandler from "@App/middlewares/OfficeMembershipHandlers/OfficeRoleHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class OfficeRolesController extends ApiController {
|
||||
constructor(private officeRolesService: OfficeRolesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all officeRoles
|
||||
*/
|
||||
@Get("/api/v1/admin/office-roles", [authHandler, roleHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query: Prisma.OfficeRolesFindManyArgs = {};
|
||||
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: {
|
||||
name: {
|
||||
contains: filter,
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId };
|
||||
if (!query.where) query.where = { office: officeWhereInput };
|
||||
query.where.office = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeRolesEntities = await this.officeRolesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeRoles = OfficeRole.hydrateArray<OfficeRole>(officeRolesEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeRoles);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new officeRole
|
||||
*/
|
||||
@Post("/api/v1/admin/office-roles", [authHandler, roleHandler, ruleHandler, officeRoleHandler])
|
||||
protected async getAddresses(req: Request, response: Response) {
|
||||
try {
|
||||
//init IOfficeRole resource with request body values
|
||||
const officeRoleEntity = OfficeRole.hydrate<OfficeRole>(req.body);
|
||||
|
||||
//validate officeRole
|
||||
await validateOrReject(officeRoleEntity, { groups: ["createOfficeRole"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeRoleEntityCreated = await this.officeRolesService.create(officeRoleEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeRole = OfficeRole.hydrate<OfficeRole>(officeRoleEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpCreated(response, officeRole);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific officeRole by uid
|
||||
*/
|
||||
@Put("/api/v1/admin/office-roles/:uid", [authHandler, roleHandler, ruleHandler, officeRoleHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const officeRoleFound = await this.officeRolesService.getByUid(uid);
|
||||
|
||||
if (!officeRoleFound) {
|
||||
this.httpNotFoundRequest(response, "officeRole not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init IOfficeRole resource with request body values
|
||||
const officeRoleEntity = OfficeRole.hydrate<OfficeRole>(req.body);
|
||||
|
||||
//validate officeRole
|
||||
await validateOrReject(officeRoleEntity, { groups: ["updateOfficeRole"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeRoleEntityUpdated = await this.officeRolesService.update(officeRoleEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeRole = OfficeRole.hydrate<OfficeRole>(officeRoleEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeRole);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific officeRole by uid
|
||||
*/
|
||||
@Get("/api/v1/admin/office-roles/:uid", [authHandler, roleHandler, ruleHandler, officeRoleHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const officeRoleEntity = await this.officeRolesService.getByUid(uid, query);
|
||||
|
||||
if (!officeRoleEntity) {
|
||||
this.httpNotFoundRequest(response, "officeRole not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeRole = OfficeRole.hydrate<OfficeRole>(officeRoleEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeRole);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
74
src/app/api/admin/OfficesController.ts
Normal file
74
src/app/api/admin/OfficesController.ts
Normal file
@ -0,0 +1,74 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import OfficesService from "@Services/admin/OfficesService/OfficesService";
|
||||
import { Service } from "typedi";
|
||||
import { Offices } from "@prisma/client";
|
||||
import { Office as OfficeResource } from "le-coffre-resources/dist/Admin";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class OfficesController extends ApiController {
|
||||
constructor(private officesService: OfficesService) {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* @description Get all offices
|
||||
*/
|
||||
@Get("/api/v1/admin/offices", [authHandler, roleHandler, ruleHandler])
|
||||
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 officesEntities: Offices[] = await this.officesService.get(query);
|
||||
//Hydrate ressource with prisma entity
|
||||
const offices = OfficeResource.hydrateArray<OfficeResource>(officesEntities, { strategy: "excludeAll" });
|
||||
//success
|
||||
this.httpSuccess(response, offices);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific office by uid
|
||||
*/
|
||||
@Get("/api/v1/admin/offices/:uid", [authHandler, roleHandler, ruleHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const officeEntity = await this.officesService.getByUid(uid, query);
|
||||
|
||||
if (!officeEntity) {
|
||||
this.httpNotFoundRequest(response, "office not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const office = OfficeResource.hydrate<OfficeResource>(officeEntity, { strategy: "excludeAll" });
|
||||
//success
|
||||
this.httpSuccess(response, office);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
78
src/app/api/admin/RolesController.ts
Normal file
78
src/app/api/admin/RolesController.ts
Normal file
@ -0,0 +1,78 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import RolesService from "@Services/admin/RolesService/RolesService";
|
||||
import { Service } from "typedi";
|
||||
import { Role } from "le-coffre-resources/dist/Admin";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class RolesController extends ApiController {
|
||||
constructor(private rolesService: RolesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all roles
|
||||
*/
|
||||
@Get("/api/v1/admin/roles", [authHandler, roleHandler, ruleHandler])
|
||||
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 rolesEntities = await this.rolesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const roles = Role.hydrateArray<Role>(rolesEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, roles);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific role by uid
|
||||
*/
|
||||
@Get("/api/v1/admin/roles/:uid", [authHandler, roleHandler, ruleHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const roleEntity = await this.rolesService.getByUid(uid, query);
|
||||
|
||||
if (!roleEntity) {
|
||||
this.httpNotFoundRequest(response, "role not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const role = Role.hydrate<Role>(roleEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, role);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
78
src/app/api/admin/RulesController.ts
Normal file
78
src/app/api/admin/RulesController.ts
Normal file
@ -0,0 +1,78 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import RulesService from "@Services/admin/RulesService/RulesService";
|
||||
import { Service } from "typedi";
|
||||
import { Rule } from "le-coffre-resources/dist/Admin";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class RulesController extends ApiController {
|
||||
constructor(private rulesService: RulesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all rules
|
||||
*/
|
||||
@Get("/api/v1/admin/rules", [authHandler, roleHandler, ruleHandler])
|
||||
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 rulesEntities = await this.rulesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const rules = Rule.hydrateArray<Rule>(rulesEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, rules);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific rule by uid
|
||||
*/
|
||||
@Get("/api/v1/admin/rules/:uid", [authHandler, roleHandler, ruleHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const ruleEntity = await this.rulesService.getByUid(uid, query);
|
||||
|
||||
if (!ruleEntity) {
|
||||
this.httpNotFoundRequest(response, "rule not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const rule = Rule.hydrate<Rule>(ruleEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, rule);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
162
src/app/api/admin/UsersController.ts
Normal file
162
src/app/api/admin/UsersController.ts
Normal file
@ -0,0 +1,162 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import UsersService from "@Services/admin/UsersService/UsersService";
|
||||
import { Service } from "typedi";
|
||||
import User from "le-coffre-resources/dist/Admin";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import userHandler from "@App/middlewares/OfficeMembershipHandlers/UserHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
import RolesService from "@Services/admin/RolesService/RolesService";
|
||||
import OfficeRolesService from "@Services/admin/OfficeRolesService/OfficeRolesService";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class UsersController extends ApiController {
|
||||
constructor(private usersService: UsersService, private roleService: RolesService, private officeRoleService: OfficeRolesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all users
|
||||
*/
|
||||
@Get("/api/v1/admin/users", [authHandler, roleHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query: Prisma.UsersFindManyArgs = {};
|
||||
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: {
|
||||
contact: {
|
||||
OR: [
|
||||
{ first_name: { contains: filter, mode: "insensitive" } },
|
||||
{ last_name: { contains: filter, mode: "insensitive" } },
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId };
|
||||
if (!query.where) query.where = { office_membership: officeWhereInput };
|
||||
query.where.office_membership = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const usersEntities = await this.usersService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const users = User.hydrateArray<User>(usersEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, users);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific user by uid
|
||||
*/
|
||||
@Put("/api/v1/admin/users/:uid", [authHandler, roleHandler, ruleHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const userFound = await this.usersService.getByUidWithRole(uid);
|
||||
|
||||
if (!userFound) {
|
||||
this.httpNotFoundRequest(response, "user not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init IUser resource with request body values
|
||||
const userEntity = User.hydrate<User>(req.body);
|
||||
|
||||
if(userEntity.role) {
|
||||
const role = await this.roleService.getByUid(userEntity.role.uid!);
|
||||
if(!role) {
|
||||
this.httpBadRequest(response, "Role not found");
|
||||
return;
|
||||
}
|
||||
if (role.name === "super-admin" || userFound.role.name === "super-admin" ) {
|
||||
this.httpBadRequest(response, "Cannot assign or remove super-admin role");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(userEntity.office_role) {
|
||||
const officeRole = await this.officeRoleService.getByUid(userEntity.office_role.uid!);
|
||||
if(!officeRole) {
|
||||
this.httpBadRequest(response, "Office role not found");
|
||||
return;
|
||||
}
|
||||
if (officeRole.office_uid != userFound.office_uid) {
|
||||
this.httpBadRequest(response, "Cannot assign an office role from another office");
|
||||
return;
|
||||
}
|
||||
}
|
||||
//call service to get prisma entity
|
||||
const userEntityUpdated = await this.usersService.update(uid, userEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const user = User.hydrate<User>(userEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, user);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific user by uid
|
||||
*/
|
||||
@Get("/api/v1/admin/users/:uid", [authHandler, roleHandler, ruleHandler, userHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const userEntity = await this.usersService.getByUid(uid, query);
|
||||
|
||||
if (!userEntity) {
|
||||
this.httpNotFoundRequest(response, "user not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const user = User.hydrate<User>(userEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, user);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,12 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import DocumentsService from "@Services/customer/DocumentsService/DocumentsService";
|
||||
import { Documents } from "@prisma/client";
|
||||
import { Documents, Prisma } from "@prisma/client";
|
||||
import { Document } from "le-coffre-resources/dist/Customer";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import documentHandler from "@App/middlewares/CustomerHandler/DocumentHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -18,108 +19,31 @@ export default class DocumentsController extends ApiController {
|
||||
* @description Get all documents
|
||||
* @returns IDocument[] list of documents
|
||||
*/
|
||||
@Get("/api/v1/customer/documents")
|
||||
@Get("/api/v1/customer/documents", [authHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
let query: Prisma.CustomersFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
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;
|
||||
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntity: Documents[] = await this.documentsService.get(query);
|
||||
const documentEntities: Documents[] = await this.documentsService.get(query);
|
||||
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documents = Document.map<Document>(Document, prismaEntity, { strategy: "excludeAll" });
|
||||
const documents = Document.hydrateArray<Document>(documentEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documents);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new document
|
||||
* @returns IDocument created
|
||||
*/
|
||||
@Post("/api/v1/customer/documents")
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init Document resource with request body values
|
||||
const documentEntity = Document.hydrate<Document>(req.body);
|
||||
|
||||
//validate document
|
||||
await validateOrReject(documentEntity, { groups: ["createDocument"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityCreated = await this.documentsService.create(documentEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documentEntityCreated = Document.hydrate<Document>(prismaEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documentEntityCreated);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Update a specific document
|
||||
*/
|
||||
@Put("/api/v1/customer/documents/:uid")
|
||||
protected async update(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
}
|
||||
|
||||
//init Document resource with request body values
|
||||
const documentEntity = new Document();
|
||||
Document.hydrate(documentEntity, req.body);
|
||||
|
||||
//validate document
|
||||
await validateOrReject(documentEntity, { groups: ["createDocument"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(prismaEntityUpdated, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a specific document
|
||||
*/
|
||||
@Delete("/api/v1/customer/documents/:uid")
|
||||
protected async delete(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntity: Documents = await this.documentsService.delete(uid);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -127,22 +51,25 @@ export default class DocumentsController extends ApiController {
|
||||
/**
|
||||
* @description Get a specific document by uid
|
||||
*/
|
||||
@Get("/api/v1/customer/documents/:uid")
|
||||
@Get("/api/v1/customer/documents/:uid",[authHandler,documentHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
let documentEntity: Documents;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
documentEntity = await this.documentsService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
documentEntity = await this.documentsService.getByUid(uid);
|
||||
const documentEntity = await this.documentsService.getByUid(uid, query);
|
||||
|
||||
if (!documentEntity) {
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
@ -151,7 +78,7 @@ export default class DocumentsController extends ApiController {
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
224
src/app/api/customer/FilesController.ts
Normal file
224
src/app/api/customer/FilesController.ts
Normal file
@ -0,0 +1,224 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import FilesService from "@Services/common/FilesService/FilesService";
|
||||
import { Files, Prisma } from "@prisma/client";
|
||||
import { File } from "le-coffre-resources/dist/Customer";
|
||||
import { Document } from "le-coffre-resources/dist/Customer";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import DocumentsService from "@Services/customer/DocumentsService/DocumentsService";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import fileHandler from "@App/middlewares/CustomerHandler/FileHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class FilesController extends ApiController {
|
||||
constructor(private filesService: FilesService, private documentService: DocumentsService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all Files
|
||||
* @returns File[] list of Files
|
||||
*/
|
||||
@Get("/api/v1/customer/files", [authHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query: Prisma.FilesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
const customerId: string = req.body.user.customerId;
|
||||
const customerWhereInput: Prisma.FilesWhereInput = { document: { depositor: { uid: customerId } } };
|
||||
query.where = customerWhereInput;
|
||||
//call service to get prisma entity
|
||||
const fileEntities = await this.filesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const files = File.hydrateArray<File>(fileEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, files);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific File by uid
|
||||
*/
|
||||
@Get("/api/v1/customer/files/download/:uid", [authHandler, fileHandler])
|
||||
protected async download(req: Request, response: Response) {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "uid not found");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const fileInfo = await this.filesService.download(uid);
|
||||
|
||||
if (!fileInfo) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
response.setHeader("Content-Type", fileInfo.file.mimetype);
|
||||
response.setHeader("Content-Disposition", `inline; filename=${encodeURIComponent(fileInfo.file.file_name)}`);
|
||||
|
||||
this.httpSuccess(response, fileInfo.buffer);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new File
|
||||
* @returns File created
|
||||
*/
|
||||
@Post("/api/v1/customer/files", [authHandler, fileHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//get file
|
||||
if (!req.file) throw new Error("No file provided");
|
||||
|
||||
//init File resource with request body values
|
||||
const fileEntity = File.hydrate<File>(JSON.parse(req.body["q"]));
|
||||
|
||||
//validate File
|
||||
await validateOrReject(fileEntity, { groups: ["createFile"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const fileEntityCreated = await this.filesService.create(fileEntity, req.file);
|
||||
|
||||
const document = await this.documentService.getByUid(fileEntity.document!.uid!);
|
||||
|
||||
const documentToUpdate = Document.hydrate<Document>(document!);
|
||||
|
||||
documentToUpdate!.document_status = "DEPOSITED";
|
||||
await this.documentService.update(document!.uid!, documentToUpdate);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const fileEntityHydrated = File.hydrate<File>(fileEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpCreated(response, fileEntityHydrated);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Update a specific file
|
||||
*/
|
||||
@Put("/api/v1/customer/files/:uid", [authHandler, fileHandler])
|
||||
protected async update(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
}
|
||||
|
||||
const fileFound = await this.filesService.getByUid(uid);
|
||||
|
||||
if (!fileFound) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init File resource with request body values
|
||||
const fileEntity = File.hydrate<File>(req.body);
|
||||
|
||||
//call service to get prisma entity
|
||||
const fileEntityUpdated: Files = await this.filesService.update(uid, fileEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const file = File.hydrate<File>(fileEntityUpdated, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, file);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a specific File
|
||||
*/
|
||||
@Delete("/api/v1/customer/files/:uid", [authHandler, fileHandler])
|
||||
protected async delete(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const fileFound = await this.filesService.getByUid(uid);
|
||||
|
||||
if (!fileFound) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const fileEntity = await this.filesService.deleteKeyAndArchive(uid);
|
||||
|
||||
if (!fileEntity) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const file = File.hydrate<File>(fileEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, file);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific File by uid
|
||||
*/
|
||||
@Get("/api/v1/customer/files/:uid", [authHandler, fileHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const fileEntity = await this.filesService.getByUid(uid, query);
|
||||
|
||||
if (!fileEntity) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const file = File.hydrate<File>(fileEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, file);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
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;
|
||||
}
|
||||
}
|
||||
}
|
63
src/app/api/franceConnect/CustomerController.ts
Normal file
63
src/app/api/franceConnect/CustomerController.ts
Normal file
@ -0,0 +1,63 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Post } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import AuthService from "@Services/common/AuthService/AuthService";
|
||||
import { JwtPayload } from "jsonwebtoken";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class CustomerController extends ApiController {
|
||||
constructor(private authService: AuthService) {
|
||||
super();
|
||||
}
|
||||
|
||||
@Post("/api/v1/france-connect/customer/login/:email")
|
||||
protected async login(req: Request, response: Response) {
|
||||
try {
|
||||
const email = req.params["email"];
|
||||
if (!email) throw new Error("email is required");
|
||||
|
||||
const payload = await this.authService.getCustomerJwtPayload(email);
|
||||
const accessToken = this.authService.generateAccessToken(payload);
|
||||
const refreshToken = this.authService.generateRefreshToken(payload);
|
||||
//success
|
||||
this.httpSuccess(response, { accessToken, refreshToken });
|
||||
} catch (error) {
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Post("/api/v1/france-connect/customer/refresh-token")
|
||||
protected async refreshToken(req: Request, response: Response) {
|
||||
try {
|
||||
const authHeader = req.headers["authorization"];
|
||||
const token = authHeader && authHeader.split(" ")[1];
|
||||
|
||||
if (!token) {
|
||||
this.httpBadRequest(response);
|
||||
return;
|
||||
}
|
||||
|
||||
let accessToken;
|
||||
this.authService.verifyRefreshToken(token, (err, customerPayload) => {
|
||||
if (err) {
|
||||
this.httpUnauthorized(response);
|
||||
return;
|
||||
}
|
||||
|
||||
const customer = customerPayload as JwtPayload;
|
||||
delete customer.iat;
|
||||
delete customer!.exp;
|
||||
accessToken = this.authService.generateAccessToken(customer);
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, accessToken);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller,Post } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import AuthService from "@Services/private-services/AuthService/AuthService";
|
||||
//import User from "le-coffre-resources/dist/Notary";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class UserInfoController extends ApiController {
|
||||
constructor(private authService: AuthService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get user created from IdNot authentification
|
||||
* @returns User
|
||||
*/
|
||||
@Post("/api/v1/idnot-user/:code")
|
||||
protected async getUserInfosFromIdnot(req: Request, response: Response) {
|
||||
try {
|
||||
const code = req.params["code"];
|
||||
const user = await this.authService.getUserFromIdNotTokens(code!);
|
||||
//success
|
||||
this.httpSuccess(response, user);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
89
src/app/api/idnot/UserController.ts
Normal file
89
src/app/api/idnot/UserController.ts
Normal file
@ -0,0 +1,89 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Post } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import AuthService from "@Services/common/AuthService/AuthService";
|
||||
import { JwtPayload } from "jsonwebtoken";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class UserController extends ApiController {
|
||||
constructor(private authService: AuthService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get user created from IdNot authentification
|
||||
* @todo Used for test, should be removed
|
||||
* @returns User
|
||||
*/
|
||||
@Post("/api/v1/idnot/user/:code")
|
||||
protected async getUserInfosFromIdnot(req: Request, response: Response) {
|
||||
console.warn("/api/v1/idnot/user/:code used for test, should be removed");
|
||||
|
||||
try {
|
||||
const code = req.params["code"];
|
||||
if (!code) throw new Error("code is required");
|
||||
const token = await fetch("https://qual-connexion.idnot.fr/IdPOAuth2/token/idnot_idp_v1", { method: "POST" });
|
||||
console.log(token);
|
||||
//const user = await this.authService.getUserFromIdNotTokens(code!);
|
||||
//success
|
||||
this.httpSuccess(response);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Post("/api/v1/idnot/user/login/:idnot")
|
||||
protected async login(req: Request, response: Response) {
|
||||
try {
|
||||
const id = req.params["idnot"];
|
||||
if (!id) throw new Error("idnot is required");
|
||||
|
||||
const payload = await this.authService.getUserJwtPayload(id);
|
||||
const accessToken = this.authService.generateAccessToken(payload);
|
||||
const refreshToken = this.authService.generateRefreshToken(payload);
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, { accessToken, refreshToken });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Post("/api/v1/idnot/user/refresh-token")
|
||||
protected async refreshToken(req: Request, response: Response) {
|
||||
try {
|
||||
const authHeader = req.headers["authorization"];
|
||||
const token = authHeader && authHeader.split(" ")[1];
|
||||
|
||||
if (!token) {
|
||||
this.httpBadRequest(response);
|
||||
return;
|
||||
}
|
||||
|
||||
let accessToken;
|
||||
this.authService.verifyRefreshToken(token, (err, userPayload) => {
|
||||
if (err) {
|
||||
this.httpUnauthorized(response);
|
||||
return;
|
||||
}
|
||||
|
||||
const user = userPayload as JwtPayload;
|
||||
delete user.iat;
|
||||
delete user!.exp;
|
||||
accessToken = this.authService.generateAccessToken(user);
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, accessToken);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
146
src/app/api/notary/CustomersController.ts
Normal file
146
src/app/api/notary/CustomersController.ts
Normal file
@ -0,0 +1,146 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import CustomersService from "@Services/notary/CustomersService/CustomersService";
|
||||
import { Service } from "typedi";
|
||||
import { Customer } from "le-coffre-resources/dist/Notary";
|
||||
import { validateOrReject } from "class-validator";
|
||||
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/notary/customers", [authHandler, ruleHandler])
|
||||
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 Create a new customer
|
||||
*/
|
||||
@Post("/api/v1/notary/customers", [authHandler, ruleHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init IUser resource with request body values
|
||||
const customerEntity = Customer.hydrate<Customer>(req.body);
|
||||
//validate user
|
||||
await validateOrReject(customerEntity, { groups: ["createCustomer"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const customerEntityCreated = await this.customersService.create(customerEntity);
|
||||
//Hydrate ressource with prisma entity
|
||||
const customer = Customer.hydrate<Customer>(customerEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpCreated(response, customer);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific customer by uid
|
||||
*/
|
||||
@Put("/api/v1/notary/customers/:uid", [authHandler, ruleHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const userFound = await this.customersService.getByUid(uid);
|
||||
|
||||
if (!userFound) {
|
||||
this.httpNotFoundRequest(response, "user not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init IUser resource with request body values
|
||||
const customerEntity = Customer.hydrate<Customer>(req.body);
|
||||
|
||||
//validate user
|
||||
await validateOrReject(customerEntity, { groups: ["updateCustomer"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const customerEntityUpdated = await this.customersService.update(uid, customerEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const customer = Customer.hydrate<Customer>(customerEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, customer);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific customer by uid
|
||||
*/
|
||||
@Get("/api/v1/notary/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;
|
||||
}
|
||||
|
||||
//get query
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
157
src/app/api/notary/DeedTypesController.ts
Normal file
157
src/app/api/notary/DeedTypesController.ts
Normal file
@ -0,0 +1,157 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import DeedTypesService from "@Services/notary/DeedTypesService/DeedTypesService";
|
||||
import { DeedTypes, Prisma } from "@prisma/client";
|
||||
import { DeedType } from "le-coffre-resources/dist/Notary";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import deedTypeHandler from "@App/middlewares/OfficeMembershipHandlers/DeedTypeHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class DeedTypesController extends ApiController {
|
||||
constructor(private deedTypesService: DeedTypesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all deedtypes
|
||||
* @returns Deedtype[] list of deedtypes
|
||||
*/
|
||||
@Get("/api/v1/notary/deed-types", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query: Prisma.DeedTypesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
if(!query.where) query.where = { office: officeWhereInput};
|
||||
query.where.office = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const deedTypeEntities: DeedTypes[] = await this.deedTypesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const DeedTypes = DeedType.hydrateArray<DeedType>(deedTypeEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, DeedTypes);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new deedtype
|
||||
* @returns Deedtype created
|
||||
*/
|
||||
@Post("/api/v1/notary/deed-types", [authHandler, ruleHandler, deedTypeHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init DeedType resource with request body values
|
||||
const deedTypeEntity = DeedType.hydrate<DeedType>(req.body);
|
||||
|
||||
//validate deed type
|
||||
await validateOrReject(deedTypeEntity, { groups: ["createDeedType"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const deedTypeEntityCreated = await this.deedTypesService.create(deedTypeEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deedType = DeedType.hydrate<DeedType>(deedTypeEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpCreated(response, deedType);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific deedtype by uid
|
||||
* @returns Deedtype modified
|
||||
*/
|
||||
@Put("/api/v1/notary/deed-types/:uid", [authHandler, ruleHandler, deedTypeHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const deedTypeFound = await this.deedTypesService.getByUid(uid);
|
||||
|
||||
if (!deedTypeFound) {
|
||||
this.httpNotFoundRequest(response, "deed type not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init DeedType resource with request body values
|
||||
const deedTypeEntity = DeedType.hydrate<DeedType>(req.body);
|
||||
|
||||
//validate deed type
|
||||
await validateOrReject(deedTypeEntity, { groups: ["updateDeedType"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const deedTypeEntityUpdated = await this.deedTypesService.update(uid, deedTypeEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deedType = DeedType.hydrate<DeedType>(deedTypeEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deedType);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific deedtype by uid
|
||||
* @returns IDeedtype
|
||||
*/
|
||||
@Get("/api/v1/notary/deed-types/:uid", [authHandler, ruleHandler, deedTypeHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const deedTypeEntity = await this.deedTypesService.getByUid(uid, query);
|
||||
|
||||
if (!deedTypeEntity) {
|
||||
this.httpNotFoundRequest(response, "deed type not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deedType = DeedType.hydrate<DeedType>(deedTypeEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deedType);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
125
src/app/api/notary/DeedsController.ts
Normal file
125
src/app/api/notary/DeedsController.ts
Normal file
@ -0,0 +1,125 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import DeedsService from "@Services/notary/DeedsService/DeedsService";
|
||||
import { Service } from "typedi";
|
||||
import { Deeds, Prisma } from "@prisma/client";
|
||||
import { Deed } from "le-coffre-resources/dist/Notary";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import deedHandler from "@App/middlewares/OfficeMembershipHandlers/DeedHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class DeedsController extends ApiController {
|
||||
constructor(private deedsService: DeedsService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all deeds
|
||||
* @returns Deed[] list of deeds
|
||||
*/
|
||||
@Get("/api/v1/notary/deeds", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query: Prisma.DeedsFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
if(!query.where) query.where = { deed_type : {office: officeWhereInput}};
|
||||
query.where.deed_type!.office = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const deedEntities: Deeds[] = await this.deedsService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deeds = Deed.hydrateArray<Deed>(deedEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deeds);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific deed by uid
|
||||
* @returns Deed
|
||||
*/
|
||||
@Get("/api/v1/notary/deeds/:uid", [authHandler, ruleHandler, deedHandler])
|
||||
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 deedEntity = await this.deedsService.getByUid(uid, query);
|
||||
|
||||
if (!deedEntity) {
|
||||
this.httpNotFoundRequest(response, "deed not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deed = Deed.hydrate<Deed>(deedEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deed);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific deed by uid
|
||||
*/
|
||||
@Put("/api/v1/notary/deeds/:uid", [authHandler, ruleHandler, deedHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const deedFound = await this.deedsService.getByUid(uid);
|
||||
|
||||
if (!deedFound) {
|
||||
this.httpNotFoundRequest(response, "deed not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init OfficeFolder resource with request body values
|
||||
const deedEntity = Deed.hydrate<Deed>(req.body);
|
||||
|
||||
//validate folder
|
||||
await validateOrReject(deedEntity, { groups: ["updateDeed"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const deedEntityUpdated = await this.deedsService.update(uid, deedEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deed = Deed.hydrate<Deed>(deedEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deed);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
146
src/app/api/notary/DocumentTypesController.ts
Normal file
146
src/app/api/notary/DocumentTypesController.ts
Normal file
@ -0,0 +1,146 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import DocumentTypesService from "@Services/notary/DocumentTypesService/DocumentTypesService";
|
||||
import { DocumentTypes, Prisma } from "@prisma/client";
|
||||
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
||||
import { DocumentType } from "le-coffre-resources/dist/Notary";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import documentTypeHandler from "@App/middlewares/OfficeMembershipHandlers/DocumentTypeHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class DocumentTypesController extends ApiController {
|
||||
constructor(private documentTypesService: DocumentTypesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all document-types
|
||||
*/
|
||||
@Get("/api/v1/notary/document-types", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query: Prisma.DocumentTypesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
if(!query.where) query.where = { office: officeWhereInput};
|
||||
query.where.office = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentTypeEntities: DocumentTypes[] = await this.documentTypesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documentTypes = DocumentType.hydrateArray<DocumentType>(documentTypeEntities, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documentTypes);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new documentType
|
||||
*/
|
||||
@Post("/api/v1/notary/document-types", [authHandler, ruleHandler, documentTypeHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init DocumentType resource with request body values
|
||||
const documentTypeEntity = DocumentType.hydrate<DocumentType>(req.body);
|
||||
//validate user
|
||||
await validateOrReject(documentTypeEntity, { groups: ["createDocumentType"], forbidUnknownValues: false });
|
||||
//call service to get prisma entity
|
||||
const documentTypeEntityCreated = await this.documentTypesService.create(documentTypeEntity);
|
||||
//Hydrate ressource with prisma entity
|
||||
const userEntityCreated = DocumentType.hydrate<DocumentType>(documentTypeEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
//success
|
||||
this.httpCreated(response, userEntityCreated);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific documentType by uid
|
||||
*/
|
||||
@Put("/api/v1/notary/document-types/:uid", [authHandler, ruleHandler, documentTypeHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const documentTypeFound = await this.documentTypesService.getByUid(uid);
|
||||
|
||||
if (!documentTypeFound) {
|
||||
this.httpNotFoundRequest(response, "document type not found");
|
||||
return;
|
||||
}
|
||||
//init DocumentType resource with request body values
|
||||
const documentTypeEntity = DocumentType.hydrate<DocumentType>(req.body);
|
||||
|
||||
//validate user
|
||||
await validateOrReject(documentTypeEntity, { groups: ["updateDocumentType"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentTypeEntityUpdated = await this.documentTypesService.update(uid, documentTypeEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documentType = DocumentType.hydrate<DocumentType>(documentTypeEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documentType);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific documentType by uid
|
||||
*/
|
||||
@Get("/api/v1/notary/document-types/:uid", [authHandler, ruleHandler, documentTypeHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const documentTypeEntity = await this.documentTypesService.getByUid(uid, query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const user = ObjectHydrate.hydrate<DocumentType>(new DocumentType(), documentTypeEntity!, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, user);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
193
src/app/api/notary/DocumentsController.ts
Normal file
193
src/app/api/notary/DocumentsController.ts
Normal file
@ -0,0 +1,193 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import DocumentsService from "@Services/notary/DocumentsService/DocumentsService";
|
||||
import { Documents, Prisma } from "@prisma/client";
|
||||
import { Document } from "le-coffre-resources/dist/Notary";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import documentHandler from "@App/middlewares/OfficeMembershipHandlers/DocumentHandler";
|
||||
import EmailBuilder from "@Common/emails/EmailBuilder";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class DocumentsController extends ApiController {
|
||||
constructor(private documentsService: DocumentsService, private emailBuilder: EmailBuilder) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all documents
|
||||
* @returns IDocument[] list of documents
|
||||
*/
|
||||
@Get("/api/v1/notary/documents", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query: Prisma.DocumentsFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
if(!query.where) query.where = { document_type : {office: officeWhereInput}};
|
||||
query.where.document_type!.office = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntities = await this.documentsService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documents = Document.hydrateArray<Document>(documentEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documents);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new document
|
||||
* @returns IDocument created
|
||||
*/
|
||||
@Post("/api/v1/notary/documents", [authHandler, ruleHandler, documentHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init Document resource with request body values
|
||||
const documentEntity = Document.hydrate<Document>(req.body);
|
||||
|
||||
//validate document
|
||||
await validateOrReject(documentEntity, { groups: ["createDocument"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntityCreated = await this.documentsService.create(documentEntity);
|
||||
|
||||
//create email for asked document
|
||||
this.emailBuilder.sendDocumentEmails(documentEntityCreated);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(documentEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpCreated(response, document);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Update a specific document
|
||||
*/
|
||||
@Put("/api/v1/notary/documents/:uid", [authHandler, ruleHandler, documentHandler])
|
||||
protected async update(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const documentFound = await this.documentsService.getByUid(uid);
|
||||
|
||||
if (!documentFound) {
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init Document resource with request body values
|
||||
const documentEntity = Document.hydrate<Document>(req.body);
|
||||
|
||||
//validate document
|
||||
await validateOrReject(documentEntity, { groups: ["updateDocument"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity, req.body.refused_reason);
|
||||
|
||||
//create email for asked document
|
||||
this.emailBuilder.sendDocumentEmails(documentEntityUpdated);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(documentEntityUpdated, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a specific document
|
||||
*/
|
||||
@Delete("/api/v1/notary/documents/:uid", [authHandler, ruleHandler, documentHandler])
|
||||
protected async delete(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const documentFound = await this.documentsService.getByUid(uid);
|
||||
|
||||
if (!documentFound) {
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntity: Documents = await this.documentsService.delete(uid);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific document by uid
|
||||
*/
|
||||
@Get("/api/v1/notary/documents/:uid", [authHandler, ruleHandler, documentHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const documentEntity = await this.documentsService.getByUid(uid, query);
|
||||
|
||||
if (!documentEntity) {
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
149
src/app/api/notary/FilesController.ts
Normal file
149
src/app/api/notary/FilesController.ts
Normal file
@ -0,0 +1,149 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import FilesService from "@Services/common/FilesService/FilesService";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { File } from "le-coffre-resources/dist/Notary";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import fileHandler from "@App/middlewares/OfficeMembershipHandlers/FileHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class FilesController extends ApiController {
|
||||
constructor(private filesService: FilesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all Files
|
||||
* @returns File[] list of Files
|
||||
*/
|
||||
@Get("/api/v1/notary/files", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query: Prisma.FilesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
if(!query.where) query.where = { document: { folder: {office: officeWhereInput}}};
|
||||
query.where.document!.folder!.office = officeWhereInput;
|
||||
//call service to get prisma entity
|
||||
const fileEntities = await this.filesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const files = File.hydrateArray<File>(fileEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, files);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific File by uid
|
||||
*/
|
||||
@Get("/api/v1/notary/files/download/:uid", [authHandler, ruleHandler, fileHandler])
|
||||
protected async download(req: Request, response: Response) {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "uid not found");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const fileInfo = await this.filesService.download(uid);
|
||||
|
||||
if (!fileInfo) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
response.setHeader("Content-Type", fileInfo.file.mimetype);
|
||||
response.setHeader("Content-Disposition", `inline; filename=${encodeURIComponent(fileInfo.file.file_name)}`);
|
||||
|
||||
this.httpSuccess(response, fileInfo.buffer);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a specific File
|
||||
*/
|
||||
@Delete("/api/v1/notary/files/:uid", [authHandler, ruleHandler, fileHandler])
|
||||
protected async delete(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const fileFound = await this.filesService.getByUid(uid);
|
||||
|
||||
if (!fileFound) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const fileEntity = await this.filesService.deleteKeyAndArchive(uid);
|
||||
|
||||
if (!fileEntity) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const file = File.hydrate<File>(fileEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, file);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific File by uid
|
||||
*/
|
||||
@Get("/api/v1/notary/files/:uid", [authHandler, ruleHandler, fileHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const fileEntity = await this.filesService.getByUid(uid, query);
|
||||
|
||||
if (!fileEntity) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const file = File.hydrate<File>(fileEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, file);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
213
src/app/api/notary/OfficeFoldersController.ts
Normal file
213
src/app/api/notary/OfficeFoldersController.ts
Normal file
@ -0,0 +1,213 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import OfficeFoldersService from "@Services/notary/OfficeFoldersService/OfficeFoldersService";
|
||||
import { Service } from "typedi";
|
||||
import { OfficeFolders, Prisma } from "@prisma/client";
|
||||
import { OfficeFolder } from "le-coffre-resources/dist/Notary";
|
||||
import { validateOrReject } from "class-validator";
|
||||
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/notary/folders", [authHandler, ruleHandler])
|
||||
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 officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
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 Create a new folder
|
||||
*/
|
||||
@Post("/api/v1/notary/folders", [authHandler, ruleHandler, folderHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init OfficeFolder resource with request body values
|
||||
const officeFolderRessource = OfficeFolder.hydrate<OfficeFolder>(req.body);
|
||||
await officeFolderRessource.validateOrReject?.({ groups: ["createFolder"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeFolderEntity = await this.officeFoldersService.create(officeFolderRessource);
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolders = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntity, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
//success
|
||||
this.httpCreated(response, officeFolders);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific folder by uid
|
||||
*/
|
||||
@Put("/api/v1/notary/folders/:uid", [authHandler, ruleHandler, folderHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const officeFolderFound = await this.officeFoldersService.getByUid(uid);
|
||||
|
||||
if (!officeFolderFound) {
|
||||
this.httpNotFoundRequest(response, "office folder not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init OfficeFolder resource with request body values
|
||||
const officeFolderEntity = OfficeFolder.hydrate<OfficeFolder>(req.body);
|
||||
|
||||
//validate folder
|
||||
await validateOrReject(officeFolderEntity, { groups: ["updateFolder"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeFolderEntityUpdated = await this.officeFoldersService.update(uid, officeFolderEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolders = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntityUpdated, {
|
||||
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/notary/folders/:uid", [authHandler, ruleHandler, folderHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
//get query
|
||||
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;
|
||||
}
|
||||
this.httpSuccess(response, await this.officeFoldersService.getByUid("uid"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a specific folder
|
||||
*/
|
||||
@Delete("/api/v1/notary/folders/:uid", [authHandler, ruleHandler, folderHandler])
|
||||
protected async delete(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const officeFolderFound = await this.officeFoldersService.getByUid(uid);
|
||||
|
||||
if (!officeFolderFound) {
|
||||
this.httpNotFoundRequest(response, "office folder not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeFoldertEntity: OfficeFolders = await this.officeFoldersService.delete(uid);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFoldertEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeFolder);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
83
src/app/api/notary/OfficeRolesController.ts
Normal file
83
src/app/api/notary/OfficeRolesController.ts
Normal file
@ -0,0 +1,83 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import OfficeRolesService from "@Services/notary/OfficeRolesService/OfficeRolesService";
|
||||
import { Service } from "typedi";
|
||||
import { OfficeRole } from "le-coffre-resources/dist/Notary";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import officeRoleHandler from "@App/middlewares/OfficeMembershipHandlers/OfficeRoleHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class OfficeRolesController extends ApiController {
|
||||
constructor(private officeRolesService: OfficeRolesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all officeRoles
|
||||
*/
|
||||
@Get("/api/v1/notary/office-roles", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query: Prisma.OfficeRolesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
if(!query.where) query.where = { office: officeWhereInput};
|
||||
query.where.office = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeRolesEntities = await this.officeRolesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeRoles = OfficeRole.hydrateArray<OfficeRole>(officeRolesEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeRoles);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific officeRole by uid
|
||||
*/
|
||||
@Get("/api/v1/notary/office-roles/:uid", [authHandler, ruleHandler, officeRoleHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const officeRoleEntity = await this.officeRolesService.getByUid(uid, query);
|
||||
|
||||
if (!officeRoleEntity) {
|
||||
this.httpNotFoundRequest(response, "officeRole not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeRole = OfficeRole.hydrate<OfficeRole>(officeRoleEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeRole);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
73
src/app/api/notary/OfficesController.ts
Normal file
73
src/app/api/notary/OfficesController.ts
Normal file
@ -0,0 +1,73 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import OfficesService from "@Services/notary/OfficesService/OfficesService";
|
||||
import { Service } from "typedi";
|
||||
import { Offices } from "@prisma/client";
|
||||
import { Office as OfficeResource } from "le-coffre-resources/dist/Notary";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class OfficesController extends ApiController {
|
||||
constructor(private officesService: OfficesService) {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* @description Get all offices
|
||||
*/
|
||||
@Get("/api/v1/notary/offices", [authHandler, ruleHandler])
|
||||
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 officesEntities: Offices[] = await this.officesService.get(query);
|
||||
//Hydrate ressource with prisma entity
|
||||
const offices = OfficeResource.hydrateArray<OfficeResource>(officesEntities, { strategy: "excludeAll" });
|
||||
//success
|
||||
this.httpSuccess(response, offices);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific office by uid
|
||||
*/
|
||||
@Get("/api/v1/notary/offices/: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;
|
||||
}
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const officeEntity = await this.officesService.getByUid(uid, query);
|
||||
|
||||
if (!officeEntity) {
|
||||
this.httpNotFoundRequest(response, "office not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const office = OfficeResource.hydrate<OfficeResource>(officeEntity, { strategy: "excludeAll" });
|
||||
//success
|
||||
this.httpSuccess(response, office);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
77
src/app/api/notary/RolesController.ts
Normal file
77
src/app/api/notary/RolesController.ts
Normal file
@ -0,0 +1,77 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import RolesService from "@Services/notary/RolesService/RolesService";
|
||||
import { Service } from "typedi";
|
||||
import { Role } from "le-coffre-resources/dist/Notary";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class RolesController extends ApiController {
|
||||
constructor(private rolesService: RolesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all roles
|
||||
*/
|
||||
@Get("/api/v1/notary/roles", [authHandler, ruleHandler])
|
||||
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 rolesEntities = await this.rolesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const roles = Role.hydrateArray<Role>(rolesEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, roles);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific role by uid
|
||||
*/
|
||||
@Get("/api/v1/notary/roles/: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;
|
||||
}
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const roleEntity = await this.rolesService.getByUid(uid, query);
|
||||
|
||||
if (!roleEntity) {
|
||||
this.httpNotFoundRequest(response, "role not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const role = Role.hydrate<Role>(roleEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, role);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
77
src/app/api/notary/RulesController.ts
Normal file
77
src/app/api/notary/RulesController.ts
Normal file
@ -0,0 +1,77 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import RulesService from "@Services/notary/RulesService/RulesService";
|
||||
import { Service } from "typedi";
|
||||
import { Rule } from "le-coffre-resources/dist/Notary";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class RulesController extends ApiController {
|
||||
constructor(private rulesService: RulesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all rules
|
||||
*/
|
||||
@Get("/api/v1/notary/rules", [authHandler, ruleHandler])
|
||||
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 rulesEntities = await this.rulesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const rules = Rule.hydrateArray<Rule>(rulesEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, rules);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific rule by uid
|
||||
*/
|
||||
@Get("/api/v1/notary/rules/: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;
|
||||
}
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const ruleEntity = await this.rulesService.getByUid(uid, query);
|
||||
|
||||
if (!ruleEntity) {
|
||||
this.httpNotFoundRequest(response, "rule not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const rule = Rule.hydrate<Rule>(ruleEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, rule);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
83
src/app/api/notary/UsersController.ts
Normal file
83
src/app/api/notary/UsersController.ts
Normal file
@ -0,0 +1,83 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import UsersService from "@Services/notary/UsersService/UsersService";
|
||||
import { Service } from "typedi";
|
||||
import User from "le-coffre-resources/dist/Notary";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import userHandler from "@App/middlewares/OfficeMembershipHandlers/UserHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class UsersController extends ApiController {
|
||||
constructor(private usersService: UsersService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all users
|
||||
*/
|
||||
@Get("/api/v1/notary/users", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query: Prisma.UsersFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
if(!query.where) query.where = { office_membership: officeWhereInput};
|
||||
query.where.office_membership = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const usersEntities = await this.usersService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const users = User.hydrateArray<User>(usersEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, users);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific user by uid
|
||||
*/
|
||||
@Get("/api/v1/notary/users/:uid", [authHandler, ruleHandler, userHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const userEntity = await this.usersService.getByUid(uid, query);
|
||||
|
||||
if (!userEntity) {
|
||||
this.httpNotFoundRequest(response, "user not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const user = User.hydrate<User>(userEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, user);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
77
src/app/api/super-admin/AppointmentsController.ts
Normal file
77
src/app/api/super-admin/AppointmentsController.ts
Normal file
@ -0,0 +1,77 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import AppointmentsService from "@Services/super-admin/AppointmentsService/AppointmentsService";
|
||||
import { Service } from "typedi";
|
||||
import { Appointment } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class AppointmentsController extends ApiController {
|
||||
constructor(private appointmentsService: AppointmentsService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all appointments
|
||||
*/
|
||||
@Get("/api/v1/super-admin/appointments", [authHandler, roleHandler])
|
||||
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 appointmentsEntities = await this.appointmentsService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const appointments = Appointment.hydrateArray<Appointment>(appointmentsEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, appointments);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific appointment by uid
|
||||
*/
|
||||
@Get("/api/v1/super-admin/appointments/:uid", [authHandler, roleHandler])
|
||||
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 appointmentEntity = await this.appointmentsService.getByUid(uid, query);
|
||||
|
||||
if (!appointmentEntity) {
|
||||
this.httpNotFoundRequest(response, "appointment not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const appointment = Appointment.hydrate<Appointment>(appointmentEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, appointment);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@ -4,8 +4,10 @@ import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import CustomersService from "@Services/super-admin/CustomersService/CustomersService";
|
||||
import { Service } from "typedi";
|
||||
import { Customer } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { Customers } from "@prisma/client";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -17,22 +19,25 @@ export default class CustomersController extends ApiController {
|
||||
/**
|
||||
* @description Get all customers
|
||||
*/
|
||||
@Get("/api/v1/super-admin/customers")
|
||||
@Get("/api/v1/super-admin/customers", [authHandler, roleHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const customersEntity = await this.customersService.get(query);
|
||||
const customersEntities = await this.customersService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const customers = Customer.map<Customer>(Customer, customersEntity, { strategy: "excludeAll" });
|
||||
const customers = Customer.hydrateArray<Customer>(customersEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, customers);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -40,7 +45,7 @@ export default class CustomersController extends ApiController {
|
||||
/**
|
||||
* @description Create a new customer
|
||||
*/
|
||||
@Post("/api/v1/super-admin/customers")
|
||||
@Post("/api/v1/super-admin/customers", [authHandler, roleHandler, ruleHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init IUser resource with request body values
|
||||
@ -49,16 +54,16 @@ export default class CustomersController extends ApiController {
|
||||
await validateOrReject(customerEntity, { groups: ["createCustomer"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityCreated = await this.customersService.create(customerEntity);
|
||||
const customerEntityCreated = await this.customersService.create(customerEntity);
|
||||
//Hydrate ressource with prisma entity
|
||||
const customerEntityCreated = Customer.hydrate<Customer>(prismaEntityCreated, {
|
||||
const customer = Customer.hydrate<Customer>(customerEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, customerEntityCreated);
|
||||
this.httpCreated(response, customer);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -66,13 +71,22 @@ export default class CustomersController extends ApiController {
|
||||
/**
|
||||
* @description Modify a specific customer by uid
|
||||
*/
|
||||
@Put("/api/v1/super-admin/customers/:uid")
|
||||
@Put("/api/v1/super-admin/customers/:uid", [authHandler, roleHandler, ruleHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const userFound = await this.customersService.getByUid(uid);
|
||||
|
||||
if (!userFound) {
|
||||
this.httpNotFoundRequest(response, "user not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init IUser resource with request body values
|
||||
const customerEntity = Customer.hydrate<Customer>(req.body);
|
||||
|
||||
@ -80,17 +94,17 @@ export default class CustomersController extends ApiController {
|
||||
await validateOrReject(customerEntity, { groups: ["updateCustomer"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityUpdated = await this.customersService.update(uid, customerEntity);
|
||||
const customerEntityUpdated = await this.customersService.update(uid, customerEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const customerEntityUpdated = Customer.hydrate<Customer>(prismaEntityUpdated, {
|
||||
const customer = Customer.hydrate<Customer>(customerEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, customerEntityUpdated);
|
||||
this.httpSuccess(response, customer);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -98,22 +112,25 @@ export default class CustomersController extends ApiController {
|
||||
/**
|
||||
* @description Get a specific customer by uid
|
||||
*/
|
||||
@Get("/api/v1/super-admin/customers/:uid")
|
||||
@Get("/api/v1/super-admin/customers/:uid", [authHandler, roleHandler, ruleHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
let customerEntity: Customers;
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
customerEntity = await this.customersService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
customerEntity = await this.customersService.getByUid(uid);
|
||||
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
|
||||
@ -122,7 +139,7 @@ export default class CustomersController extends ApiController {
|
||||
//success
|
||||
this.httpSuccess(response, customer);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,13 @@ import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import DeedTypesService from "@Services/super-admin/DeedTypesService/DeedTypesService";
|
||||
import { DeedTypes } from "@prisma/client";
|
||||
import { DeedTypes, Prisma } from "@prisma/client";
|
||||
import { DeedType } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import deedTypeHandler from "@App/middlewares/OfficeMembershipHandlers/DeedTypeHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -18,21 +22,42 @@ export default class DeedTypesController extends ApiController {
|
||||
* @description Get all deedtypes
|
||||
* @returns Deedtype[] list of deedtypes
|
||||
*/
|
||||
@Get("/api/v1/super-admin/deed-types")
|
||||
@Get("/api/v1/super-admin/deed-types", [authHandler, roleHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
let query: Prisma.DeedTypesFindManyArgs = {};
|
||||
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: {
|
||||
name: {
|
||||
contains: filter,
|
||||
mode: "insensitive",
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
if(!query.where) query.where = { office: officeWhereInput};
|
||||
query.where.office = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntity: DeedTypes[] = await this.deedTypesService.get(query);
|
||||
const deedTypeEntities: DeedTypes[] = await this.deedTypesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const DeedTypes = DeedType.map<DeedType>(DeedType, prismaEntity, { strategy: "excludeAll" });
|
||||
const DeedTypes = DeedType.hydrateArray<DeedType>(deedTypeEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, DeedTypes);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -41,7 +66,7 @@ export default class DeedTypesController extends ApiController {
|
||||
* @description Create a new deedtype
|
||||
* @returns Deedtype created
|
||||
*/
|
||||
@Post("/api/v1/super-admin/deed-types")
|
||||
@Post("/api/v1/super-admin/deed-types", [authHandler, roleHandler, ruleHandler, deedTypeHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init DeedType resource with request body values
|
||||
@ -51,17 +76,17 @@ export default class DeedTypesController extends ApiController {
|
||||
await validateOrReject(deedTypeEntity, { groups: ["createDeedType"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityCreated = await this.deedTypesService.create(deedTypeEntity);
|
||||
const deedTypeEntityCreated = await this.deedTypesService.create(deedTypeEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deedTypeEntityCreated = DeedType.hydrate<DeedType>(prismaEntityCreated, {
|
||||
const deedType = DeedType.hydrate<DeedType>(deedTypeEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deedTypeEntityCreated);
|
||||
this.httpCreated(response, deedType);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -70,13 +95,22 @@ export default class DeedTypesController extends ApiController {
|
||||
* @description Modify a specific deedtype by uid
|
||||
* @returns Deedtype modified
|
||||
*/
|
||||
@Put("/api/v1/super-admin/deed-types/:uid")
|
||||
@Put("/api/v1/super-admin/deed-types/:uid", [authHandler, roleHandler, ruleHandler, deedTypeHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const deedTypeFound = await this.deedTypesService.getByUid(uid);
|
||||
|
||||
if (!deedTypeFound) {
|
||||
this.httpNotFoundRequest(response, "deed type not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init DeedType resource with request body values
|
||||
const deedTypeEntity = DeedType.hydrate<DeedType>(req.body);
|
||||
|
||||
@ -84,17 +118,17 @@ export default class DeedTypesController extends ApiController {
|
||||
await validateOrReject(deedTypeEntity, { groups: ["updateDeedType"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityUpdated = await this.deedTypesService.update(uid, deedTypeEntity);
|
||||
const deedTypeEntityUpdated = await this.deedTypesService.update(uid, deedTypeEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deedTypeEntityUpdated = DeedType.hydrate<DeedType>(prismaEntityUpdated, {
|
||||
const deedType = DeedType.hydrate<DeedType>(deedTypeEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deedTypeEntityUpdated);
|
||||
this.httpSuccess(response, deedType);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -103,22 +137,26 @@ export default class DeedTypesController extends ApiController {
|
||||
* @description Get a specific deedtype by uid
|
||||
* @returns IDeedtype
|
||||
*/
|
||||
@Get("/api/v1/super-admin/deed-types/:uid")
|
||||
@Get("/api/v1/super-admin/deed-types/:uid", [authHandler, roleHandler, ruleHandler, deedTypeHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
let deedTypeEntity: DeedTypes;
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
deedTypeEntity = await this.deedTypesService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
deedTypeEntity = await this.deedTypesService.getByUid(uid);
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const deedTypeEntity = await this.deedTypesService.getByUid(uid, query);
|
||||
|
||||
|
||||
if (!deedTypeEntity) {
|
||||
this.httpNotFoundRequest(response, "deed type not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
@ -127,7 +165,7 @@ export default class DeedTypesController extends ApiController {
|
||||
//success
|
||||
this.httpSuccess(response, deedType);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,13 @@ import { Controller, Get, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import DeedsService from "@Services/super-admin/DeedsService/DeedsService";
|
||||
import { Service } from "typedi";
|
||||
import { Deeds } from "@prisma/client";
|
||||
import { Deeds, Prisma } from "@prisma/client";
|
||||
import { Deed } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import deedHandler from "@App/middlewares/OfficeMembershipHandlers/DeedHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -18,21 +22,29 @@ export default class DeedsController extends ApiController {
|
||||
* @description Get all deeds
|
||||
* @returns Deed[] list of deeds
|
||||
*/
|
||||
@Get("/api/v1/super-admin/deeds")
|
||||
@Get("/api/v1/super-admin/deeds", [authHandler, roleHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
let query: Prisma.DeedsFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
if(!query.where) query.where = { deed_type : {office: officeWhereInput}};
|
||||
query.where.deed_type!.office = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntity: Deeds[] = await this.deedsService.get(query);
|
||||
const deedEntities: Deeds[] = await this.deedsService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deeds = Deed.map<Deed>(Deed, prismaEntity, { strategy: "excludeAll" });
|
||||
const deeds = Deed.hydrateArray<Deed>(deedEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deeds);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -41,22 +53,25 @@ export default class DeedsController extends ApiController {
|
||||
* @description Get a specific deed by uid
|
||||
* @returns Deed
|
||||
*/
|
||||
@Get("/api/v1/super-admin/deeds/:uid")
|
||||
@Get("/api/v1/super-admin/deeds/:uid", [authHandler, roleHandler, ruleHandler, deedHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
let deedEntity: Deeds;
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
deedEntity = await this.deedsService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
deedEntity = await this.deedsService.getByUid(uid);
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const deedEntity = await this.deedsService.getByUid(uid, query);
|
||||
|
||||
if (!deedEntity) {
|
||||
this.httpNotFoundRequest(response, "deed not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
@ -65,7 +80,7 @@ export default class DeedsController extends ApiController {
|
||||
//success
|
||||
this.httpSuccess(response, deed);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -73,13 +88,22 @@ export default class DeedsController extends ApiController {
|
||||
/**
|
||||
* @description Modify a specific deed by uid
|
||||
*/
|
||||
@Put("/api/v1/super-admin/deeds/:uid")
|
||||
@Put("/api/v1/super-admin/deeds/:uid", [authHandler, roleHandler, ruleHandler, deedHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const deedFound = await this.deedsService.getByUid(uid);
|
||||
|
||||
if (!deedFound) {
|
||||
this.httpNotFoundRequest(response, "deed not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init OfficeFolder resource with request body values
|
||||
const deedEntity = Deed.hydrate<Deed>(req.body);
|
||||
|
||||
@ -87,17 +111,17 @@ export default class DeedsController extends ApiController {
|
||||
await validateOrReject(deedEntity, { groups: ["updateDeed"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityUpdated = await this.deedsService.update(uid, deedEntity);
|
||||
const deedEntityUpdated = await this.deedsService.update(uid, deedEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deedEntityUpdated = Deed.hydrate<Deed>(prismaEntityUpdated, {
|
||||
const deed = Deed.hydrate<Deed>(deedEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deedEntityUpdated);
|
||||
this.httpSuccess(response, deed);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,14 @@ import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import DocumentTypesService from "@Services/super-admin/DocumentTypesService/DocumentTypesService";
|
||||
import { DocumentTypes } from "@prisma/client";
|
||||
import { DocumentTypes, Prisma } from "@prisma/client";
|
||||
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
||||
import { DocumentType } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import documentTypeHandler from "@App/middlewares/OfficeMembershipHandlers/DocumentTypeHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -18,24 +22,31 @@ export default class DocumentTypesController extends ApiController {
|
||||
/**
|
||||
* @description Get all document-types
|
||||
*/
|
||||
@Get("/api/v1/super-admin/document-types")
|
||||
@Get("/api/v1/super-admin/document-types", [authHandler, roleHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
let query: Prisma.DocumentTypesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
if(!query.where) query.where = { office: officeWhereInput};
|
||||
query.where.office = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntity: DocumentTypes[] = await this.documentTypesService.get(query);
|
||||
const documentTypeEntities: DocumentTypes[] = await this.documentTypesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documentTypes = DocumentType.map<DocumentType>(DocumentType, prismaEntity, {
|
||||
const documentTypes = DocumentType.hydrateArray<DocumentType>(documentTypeEntities, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documentTypes);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -43,23 +54,28 @@ export default class DocumentTypesController extends ApiController {
|
||||
/**
|
||||
* @description Create a new documentType
|
||||
*/
|
||||
@Post("/api/v1/super-admin/document-types")
|
||||
@Post("/api/v1/super-admin/document-types", [authHandler, roleHandler, ruleHandler, documentTypeHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init DocumentType resource with request body values
|
||||
const documentTypeEntity = DocumentType.hydrate<DocumentType>(req.body);
|
||||
const doesExist = await this.documentTypesService.get({ where: { name: documentTypeEntity.name } });
|
||||
if (doesExist.length > 0) {
|
||||
this.httpBadRequest(response, "Document type name already used");
|
||||
return;
|
||||
}
|
||||
//validate user
|
||||
await validateOrReject(documentTypeEntity, { groups: ["createDocumentType"], forbidUnknownValues: false });
|
||||
//call service to get prisma entity
|
||||
const prismaEntityCreated = await this.documentTypesService.create(documentTypeEntity);
|
||||
const documentTypeEntityCreated = await this.documentTypesService.create(documentTypeEntity);
|
||||
//Hydrate ressource with prisma entity
|
||||
const userEntityCreated = DocumentType.hydrate<DocumentType>(prismaEntityCreated, {
|
||||
const userEntityCreated = DocumentType.hydrate<DocumentType>(documentTypeEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
//success
|
||||
this.httpSuccess(response, userEntityCreated);
|
||||
this.httpCreated(response, userEntityCreated);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -67,31 +83,39 @@ export default class DocumentTypesController extends ApiController {
|
||||
/**
|
||||
* @description Modify a specific documentType by uid
|
||||
*/
|
||||
@Put("/api/v1/super-admin/document-types/:uid")
|
||||
@Put("/api/v1/super-admin/document-types/:uid", [authHandler, roleHandler, ruleHandler, documentTypeHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const documentTypeFound = await this.documentTypesService.getByUid(uid);
|
||||
|
||||
if (!documentTypeFound) {
|
||||
this.httpNotFoundRequest(response, "document type not found");
|
||||
return;
|
||||
}
|
||||
//init DocumentType resource with request body values
|
||||
const documentTypeEntity = DocumentType.hydrate<DocumentType>(req.body);
|
||||
|
||||
//validate user
|
||||
await validateOrReject(documentTypeEntity, { groups: ["update"] });
|
||||
await validateOrReject(documentTypeEntity, { groups: ["updateDocumentType"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityUpdated = await this.documentTypesService.update(uid, documentTypeEntity);
|
||||
const documentTypeEntityUpdated = await this.documentTypesService.update(uid, documentTypeEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documentTypeEntityUpdated = DocumentType.hydrate<DocumentType>(prismaEntityUpdated, {
|
||||
const documentType = DocumentType.hydrate<DocumentType>(documentTypeEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documentTypeEntityUpdated);
|
||||
this.httpSuccess(response, documentType);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -99,31 +123,29 @@ export default class DocumentTypesController extends ApiController {
|
||||
/**
|
||||
* @description Get a specific documentType by uid
|
||||
*/
|
||||
@Get("/api/v1/super-admin/document-types/:uid")
|
||||
@Get("/api/v1/super-admin/document-types/:uid", [authHandler, roleHandler, ruleHandler, documentTypeHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
let documentTypeEntity: DocumentTypes;
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
documentTypeEntity = await this.documentTypesService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
documentTypeEntity = await this.documentTypesService.getByUid(uid);
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const documentTypeEntity = await this.documentTypesService.getByUid(uid, query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const user = ObjectHydrate.hydrate<DocumentType>(new DocumentType(), documentTypeEntity, { strategy: "excludeAll" });
|
||||
const user = ObjectHydrate.hydrate<DocumentType>(new DocumentType(), documentTypeEntity!, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, user);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,15 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import documentHandler from "@App/middlewares/OfficeMembershipHandlers/DocumentHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import { Documents, Prisma } from "@prisma/client";
|
||||
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
|
||||
import { Documents } from "@prisma/client";
|
||||
import { Document } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import { Request, Response } from "express";
|
||||
import { Document } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { Service } from "typedi";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -18,22 +22,33 @@ export default class DocumentsController extends ApiController {
|
||||
* @description Get all documents
|
||||
* @returns IDocument[] list of documents
|
||||
*/
|
||||
@Get("/api/v1/super-admin/documents")
|
||||
@Get("/api/v1/super-admin/documents", [authHandler, roleHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
let query: Prisma.DocumentsFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
|
||||
if(!query.where) query.where = { document_type : {office: officeWhereInput}};
|
||||
|
||||
// query.where.document_type!.office = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntity: Documents[] = await this.documentsService.get(query);
|
||||
|
||||
const documentEntities = await this.documentsService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documents = Document.map<Document>(Document, prismaEntity, { strategy: "excludeAll" });
|
||||
const documents = Document.hydrateArray<Document>(documentEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documents);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -42,7 +57,7 @@ export default class DocumentsController extends ApiController {
|
||||
* @description Create a new document
|
||||
* @returns IDocument created
|
||||
*/
|
||||
@Post("/api/v1/super-admin/documents")
|
||||
@Post("/api/v1/super-admin/documents", [authHandler, roleHandler, ruleHandler, documentHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init Document resource with request body values
|
||||
@ -52,17 +67,17 @@ export default class DocumentsController extends ApiController {
|
||||
await validateOrReject(documentEntity, { groups: ["createDocument"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityCreated = await this.documentsService.create(documentEntity);
|
||||
const documentEntityCreated = await this.documentsService.create(documentEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documentEntityCreated = Document.hydrate<Document>(prismaEntityCreated, {
|
||||
const document = Document.hydrate<Document>(documentEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documentEntityCreated);
|
||||
this.httpCreated(response, document);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -70,12 +85,20 @@ export default class DocumentsController extends ApiController {
|
||||
/**
|
||||
* @description Update a specific document
|
||||
*/
|
||||
@Put("/api/v1/super-admin/documents/:uid")
|
||||
@Put("/api/v1/super-admin/documents/:uid", [authHandler, roleHandler, ruleHandler, documentHandler])
|
||||
protected async update(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const documentFound = await this.documentsService.getByUid(uid);
|
||||
|
||||
if (!documentFound) {
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init Document resource with request body values
|
||||
@ -85,15 +108,15 @@ export default class DocumentsController extends ApiController {
|
||||
await validateOrReject(documentEntity, { groups: ["updateDocument"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity, req.body.refused_reason);
|
||||
const documentEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity, req.body.refused_reason);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(prismaEntityUpdated, { strategy: "excludeAll" });
|
||||
const document = Document.hydrate<Document>(documentEntityUpdated, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -101,12 +124,20 @@ export default class DocumentsController extends ApiController {
|
||||
/**
|
||||
* @description Delete a specific document
|
||||
*/
|
||||
@Delete("/api/v1/super-admin/documents/:uid")
|
||||
@Delete("/api/v1/super-admin/documents/:uid", [authHandler, roleHandler, ruleHandler, documentHandler])
|
||||
protected async delete(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const documentFound = await this.documentsService.getByUid(uid);
|
||||
|
||||
if (!documentFound) {
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
@ -118,7 +149,7 @@ export default class DocumentsController extends ApiController {
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -126,22 +157,25 @@ export default class DocumentsController extends ApiController {
|
||||
/**
|
||||
* @description Get a specific document by uid
|
||||
*/
|
||||
@Get("/api/v1/super-admin/documents/:uid")
|
||||
@Get("/api/v1/super-admin/documents/:uid", [authHandler, roleHandler, ruleHandler, documentHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
let documentEntity: Documents;
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
documentEntity = await this.documentsService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
documentEntity = await this.documentsService.getByUid(uid);
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const documentEntity = await this.documentsService.getByUid(uid, query);
|
||||
|
||||
if (!documentEntity) {
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
@ -150,7 +184,7 @@ export default class DocumentsController extends ApiController {
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,19 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import { Controller, Delete, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import FilesService from "@Services/private-services/FilesService/FilesService";
|
||||
import { Files } from "@prisma/client";
|
||||
import { File, Document } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
|
||||
import FilesService from "@Services/common/FilesService/FilesService";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { File } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import fileHandler from "@App/middlewares/OfficeMembershipHandlers/FileHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class FilesController extends ApiController {
|
||||
constructor(private filesService: FilesService, private documentService: DocumentsService) {
|
||||
constructor(private filesService: FilesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
@ -19,17 +21,24 @@ export default class FilesController extends ApiController {
|
||||
* @description Get all Files
|
||||
* @returns File[] list of Files
|
||||
*/
|
||||
@Get("/api/v1/super-admin/files")
|
||||
@Get("/api/v1/super-admin/files", [authHandler, roleHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
let query: Prisma.FilesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
if(!query.where) query.where = { document: { folder: {office: officeWhereInput}}};
|
||||
query.where.document!.folder!.office = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntity = await this.filesService.get(query);
|
||||
const fileEntities = await this.filesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const files = File.map<File>(File, prismaEntity, { strategy: "excludeAll" });
|
||||
const files = File.hydrateArray<File>(fileEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, files);
|
||||
@ -42,87 +51,27 @@ export default class FilesController extends ApiController {
|
||||
/**
|
||||
* @description Get a specific File by uid
|
||||
*/
|
||||
@Get("/api/v1/super-admin/files/upload/:uid")
|
||||
protected async getFileData(req: Request, response: Response) {
|
||||
try {
|
||||
@Get("/api/v1/super-admin/files/download/:uid", [authHandler, roleHandler, ruleHandler, fileHandler])
|
||||
protected async download(req: Request, response: Response) {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
}
|
||||
|
||||
const file = await this.filesService.updload(uid);
|
||||
|
||||
this.httpSuccess(response, file);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpBadRequest(response, "uid not found");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new File
|
||||
* @returns File created
|
||||
*/
|
||||
@Post("/api/v1/super-admin/files")
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
const fileInfo = await this.filesService.download(uid);
|
||||
|
||||
//get file
|
||||
if(!req.file) throw new Error('No file provided')
|
||||
|
||||
//init File resource with request body values
|
||||
const fileEntity = File.hydrate<File>(JSON.parse(req.body["q"]));
|
||||
|
||||
//validate File
|
||||
await validateOrReject(fileEntity, { groups: ["createFile"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityCreated = await this.filesService.create(fileEntity, req.file);
|
||||
|
||||
const document: Document = await this.documentService.getByUid(fileEntity.document!.uid!)
|
||||
document.document_status = "DEPOSITED";
|
||||
await this.documentService.update(document.uid!, document);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const fileEntityCreated = File.hydrate<File>(prismaEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, fileEntityCreated);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
if (!fileInfo) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Update a specific file
|
||||
*/
|
||||
@Put("/api/v1/super-admin/files/:uid")
|
||||
protected async update(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
}
|
||||
response.setHeader("Content-Type", fileInfo.file.mimetype);
|
||||
response.setHeader("Content-Disposition", `inline; filename=${encodeURIComponent(fileInfo.file.file_name)}`);
|
||||
|
||||
//init File resource with request body values
|
||||
const fileEntity = File.hydrate<File>(req.body);
|
||||
|
||||
//validate file
|
||||
await validateOrReject(fileEntity, { groups: ["updateFile"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityUpdated: Files = await this.filesService.update(uid, fileEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const file = File.hydrate<File>(prismaEntityUpdated, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, file);
|
||||
this.httpSuccess(response, fileInfo.buffer);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -130,16 +79,29 @@ export default class FilesController extends ApiController {
|
||||
/**
|
||||
* @description Delete a specific File
|
||||
*/
|
||||
@Delete("/api/v1/super-admin/files/:uid")
|
||||
@Delete("/api/v1/super-admin/files/:uid", [authHandler, roleHandler, ruleHandler, fileHandler])
|
||||
protected async delete(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const fileFound = await this.filesService.getByUid(uid);
|
||||
|
||||
if (!fileFound) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const fileEntity: Files = await this.filesService.delete(uid);
|
||||
const fileEntity = await this.filesService.deleteKeyAndArchive(uid);
|
||||
|
||||
if (!fileEntity) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const file = File.hydrate<File>(fileEntity, { strategy: "excludeAll" });
|
||||
@ -147,7 +109,7 @@ export default class FilesController extends ApiController {
|
||||
//success
|
||||
this.httpSuccess(response, file);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -155,15 +117,26 @@ export default class FilesController extends ApiController {
|
||||
/**
|
||||
* @description Get a specific File by uid
|
||||
*/
|
||||
@Get("/api/v1/super-admin/files/:uid")
|
||||
@Get("/api/v1/super-admin/files/:uid", [authHandler, roleHandler, ruleHandler, fileHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const fileEntity = await this.filesService.getByUid(uid);
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const fileEntity = await this.filesService.getByUid(uid, query);
|
||||
|
||||
if (!fileEntity) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const file = File.hydrate<File>(fileEntity, { strategy: "excludeAll" });
|
||||
@ -171,7 +144,7 @@ export default class FilesController extends ApiController {
|
||||
//success
|
||||
this.httpSuccess(response, file);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
95
src/app/api/super-admin/LiveVoteController.ts
Normal file
95
src/app/api/super-admin/LiveVoteController.ts
Normal file
@ -0,0 +1,95 @@
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Controller, Post } from "@ControllerPattern/index";
|
||||
import { EAppointmentStatus } from "@prisma/client";
|
||||
import AppointmentService from "@Services/super-admin/AppointmentsService/AppointmentsService";
|
||||
import LiveVoteService from "@Services/super-admin/LiveVoteService/LiveVoteService";
|
||||
import UsersService from "@Services/super-admin/UsersService/UsersService";
|
||||
import VotesService from "@Services/super-admin/VotesService/VotesService";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import { Request, Response } from "express";
|
||||
import { Vote } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { Service } from "typedi";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class LiveVoteController extends ApiController {
|
||||
constructor(
|
||||
private liveVoteService: LiveVoteService,
|
||||
private votesService: VotesService,
|
||||
private usersService: UsersService,
|
||||
private appointmentService: AppointmentService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new vote
|
||||
*/
|
||||
@Post("/api/v1/super-admin/live-votes", [authHandler, roleHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
const userId = req.body.user.userId;
|
||||
//init IUser resource with request body values
|
||||
const voteEntity = Vote.hydrate<Vote>(req.body);
|
||||
//validate user
|
||||
await validateOrReject(voteEntity, { groups: ["createVote"] });
|
||||
|
||||
let voteFound = [];
|
||||
if (voteEntity.appointment.uid) {
|
||||
const appointment = await this.appointmentService.getByUid(voteEntity.appointment.uid);
|
||||
if (!appointment) {
|
||||
this.httpNotFoundRequest(response, "Appointment not found");
|
||||
return;
|
||||
}
|
||||
if (appointment.status === EAppointmentStatus.CLOSED) {
|
||||
this.httpBadRequest(response, "Appointment is closed");
|
||||
return;
|
||||
}
|
||||
voteFound = await this.votesService.get({
|
||||
where: { AND: [{ appointment: { uid: voteEntity.appointment.uid } }, { voter: { uid: userId } }] },
|
||||
});
|
||||
} else {
|
||||
voteFound = await this.votesService.get({
|
||||
where: {
|
||||
AND: [
|
||||
{
|
||||
appointment: {
|
||||
AND: [{ user_uid: voteEntity.appointment.targeted_user.uid }, { status: EAppointmentStatus.OPEN }],
|
||||
},
|
||||
},
|
||||
{ voter: { uid: userId } },
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (voteFound.length) {
|
||||
this.httpBadRequest(response, "Voter already voted for this appointment");
|
||||
return;
|
||||
}
|
||||
|
||||
const voter = await this.usersService.getByUid(userId);
|
||||
|
||||
voteEntity.voter = voter!;
|
||||
//call service to get prisma entity
|
||||
const voteEntityCreated = await this.liveVoteService.create(voteEntity);
|
||||
|
||||
if (!voteEntityCreated) {
|
||||
this.httpBadRequest(response, "Appointment choice is not valid");
|
||||
return;
|
||||
}
|
||||
//Hydrate ressource with prisma entity
|
||||
const vote = Vote.hydrate<Vote>(voteEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpCreated(response, vote);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,9 +3,13 @@ import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import OfficeFoldersService from "@Services/super-admin/OfficeFoldersService/OfficeFoldersService";
|
||||
import { Service } from "typedi";
|
||||
import { OfficeFolders } from "@prisma/client";
|
||||
import { OfficeFolders, Prisma } from "@prisma/client";
|
||||
import { OfficeFolder } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import folderHandler from "@App/middlewares/OfficeMembershipHandlers/FolderHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -17,21 +21,58 @@ export default class OfficeFoldersController extends ApiController {
|
||||
/**
|
||||
* @description Get all folders
|
||||
*/
|
||||
@Get("/api/v1/super-admin/folders")
|
||||
@Get("/api/v1/super-admin/folders", [authHandler, roleHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
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 officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId };
|
||||
if (!query.where) query.where = { office: officeWhereInput };
|
||||
query.where.office = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntity: OfficeFolders[] = await this.officeFoldersService.get(query);
|
||||
const officeFolderEntities: OfficeFolders[] = await this.officeFoldersService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolders = OfficeFolder.map<OfficeFolder>(OfficeFolder, prismaEntity, {
|
||||
const officeFolders = OfficeFolder.hydrateArray<OfficeFolder>(officeFolderEntities, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
//success
|
||||
this.httpSuccess(response, officeFolders);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -39,24 +80,23 @@ export default class OfficeFoldersController extends ApiController {
|
||||
/**
|
||||
* @description Create a new folder
|
||||
*/
|
||||
@Post("/api/v1/super-admin/folders")
|
||||
@Post("/api/v1/super-admin/folders", [authHandler, roleHandler, ruleHandler, folderHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init OfficeFolder resource with request body values
|
||||
const officeFolderEntity = OfficeFolder.hydrate<OfficeFolder>(req.body);
|
||||
const officeFolderRessource = OfficeFolder.hydrate<OfficeFolder>(req.body);
|
||||
await officeFolderRessource.validateOrReject?.({ groups: ["createFolder"], forbidUnknownValues: false });
|
||||
|
||||
//validate folder
|
||||
await validateOrReject(officeFolderEntity, { groups: ["createFolder"] , forbidUnknownValues: false });
|
||||
//call service to get prisma entity
|
||||
const prismaEntityCreated = await this.officeFoldersService.create(officeFolderEntity);
|
||||
const officeFolderEntity = await this.officeFoldersService.create(officeFolderRessource);
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolderEntityCreated = OfficeFolder.hydrate<OfficeFolder>(prismaEntityCreated, {
|
||||
const officeFolders = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntity, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
//success
|
||||
this.httpSuccess(response, officeFolderEntityCreated);
|
||||
this.httpCreated(response, officeFolders);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -64,13 +104,22 @@ export default class OfficeFoldersController extends ApiController {
|
||||
/**
|
||||
* @description Modify a specific folder by uid
|
||||
*/
|
||||
@Put("/api/v1/super-admin/folders/:uid")
|
||||
@Put("/api/v1/super-admin/folders/:uid", [authHandler, roleHandler, ruleHandler, folderHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const officeFolderFound = await this.officeFoldersService.getByUid(uid);
|
||||
|
||||
if (!officeFolderFound) {
|
||||
this.httpNotFoundRequest(response, "office folder not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init OfficeFolder resource with request body values
|
||||
const officeFolderEntity = OfficeFolder.hydrate<OfficeFolder>(req.body);
|
||||
|
||||
@ -78,17 +127,17 @@ export default class OfficeFoldersController extends ApiController {
|
||||
await validateOrReject(officeFolderEntity, { groups: ["updateFolder"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityUpdated = await this.officeFoldersService.update(uid, officeFolderEntity);
|
||||
const officeFolderEntityUpdated = await this.officeFoldersService.update(uid, officeFolderEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolderEntityUpdated = OfficeFolder.hydrate<OfficeFolder>(prismaEntityUpdated, {
|
||||
const officeFolders = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeFolderEntityUpdated);
|
||||
this.httpSuccess(response, officeFolders);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -97,22 +146,25 @@ export default class OfficeFoldersController extends ApiController {
|
||||
* @description Get a specific folder by uid
|
||||
* @returns IFolder
|
||||
*/
|
||||
@Get("/api/v1/super-admin/folders/:uid")
|
||||
@Get("/api/v1/super-admin/folders/:uid", [authHandler, roleHandler, ruleHandler, folderHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
let officeFolderEntity: OfficeFolders;
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
officeFolderEntity = await this.officeFoldersService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
officeFolderEntity = await this.officeFoldersService.getByUid(uid);
|
||||
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
|
||||
@ -121,21 +173,28 @@ export default class OfficeFoldersController extends ApiController {
|
||||
//success
|
||||
this.httpSuccess(response, officeFolder);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
this.httpSuccess(response, await this.officeFoldersService.getByUid("uid"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a specific folder
|
||||
*/
|
||||
@Delete("/api/v1/super-admin/folders/:uid")
|
||||
@Delete("/api/v1/super-admin/folders/:uid", [authHandler, roleHandler, ruleHandler, folderHandler])
|
||||
protected async delete(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const officeFolderFound = await this.officeFoldersService.getByUid(uid);
|
||||
|
||||
if (!officeFolderFound) {
|
||||
this.httpNotFoundRequest(response, "office folder not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
@ -147,7 +206,7 @@ export default class OfficeFoldersController extends ApiController {
|
||||
//success
|
||||
this.httpSuccess(response, officeFolder);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
166
src/app/api/super-admin/OfficeRolesController.ts
Normal file
166
src/app/api/super-admin/OfficeRolesController.ts
Normal file
@ -0,0 +1,166 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import OfficeRolesService from "@Services/super-admin/OfficeRolesService/OfficeRolesService";
|
||||
import { Service } from "typedi";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import { OfficeRole } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import officeRoleHandler from "@App/middlewares/OfficeMembershipHandlers/OfficeRoleHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class OfficeRolesController extends ApiController {
|
||||
constructor(private officeRolesService: OfficeRolesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all officeRoles
|
||||
*/
|
||||
@Get("/api/v1/super-admin/office-roles", [authHandler, roleHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query: Prisma.OfficeRolesFindManyArgs = {};
|
||||
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: {
|
||||
name: {
|
||||
contains: filter,
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
if(!query.where) query.where = { office: officeWhereInput};
|
||||
query.where.office = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeRolesEntities = await this.officeRolesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeRoles = OfficeRole.hydrateArray<OfficeRole>(officeRolesEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeRoles);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new officeRole
|
||||
*/
|
||||
@Post("/api/v1/super-admin/office-roles", [authHandler, roleHandler, ruleHandler, officeRoleHandler])
|
||||
protected async getAddresses(req: Request, response: Response) {
|
||||
try {
|
||||
//init IOfficeRole resource with request body values
|
||||
const officeRoleEntity = OfficeRole.hydrate<OfficeRole>(req.body);
|
||||
|
||||
//validate officeRole
|
||||
await validateOrReject(officeRoleEntity, { groups: ["createOfficeRole"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeRoleEntityCreated = await this.officeRolesService.create(officeRoleEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeRole = OfficeRole.hydrate<OfficeRole>(officeRoleEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpCreated(response, officeRole);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific officeRole by uid
|
||||
*/
|
||||
@Put("/api/v1/super-admin/office-roles/:uid", [authHandler, roleHandler, ruleHandler, officeRoleHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const officeRoleFound = await this.officeRolesService.getByUid(uid);
|
||||
|
||||
if (!officeRoleFound) {
|
||||
this.httpNotFoundRequest(response, "officeRole not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init IOfficeRole resource with request body values
|
||||
const officeRoleEntity = OfficeRole.hydrate<OfficeRole>(req.body);
|
||||
|
||||
//validate officeRole
|
||||
await validateOrReject(officeRoleEntity, { groups: ["updateOfficeRole"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeRoleEntityUpdated = await this.officeRolesService.update(officeRoleEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeRole = OfficeRole.hydrate<OfficeRole>(officeRoleEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeRole);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific officeRole by uid
|
||||
*/
|
||||
@Get("/api/v1/super-admin/office-roles/:uid", [authHandler, roleHandler, ruleHandler, officeRoleHandler])
|
||||
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 officeRoleEntity = await this.officeRolesService.getByUid(uid, query);
|
||||
|
||||
if (!officeRoleEntity) {
|
||||
this.httpNotFoundRequest(response, "officeRole not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeRole = OfficeRole.hydrate<OfficeRole>(officeRoleEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeRole);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,9 @@ import { Service } from "typedi";
|
||||
import { Offices } from "@prisma/client";
|
||||
import { Office as OfficeResource } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -16,26 +19,42 @@ export default class OfficesController extends ApiController {
|
||||
/**
|
||||
* @description Get all offices
|
||||
*/
|
||||
@Get("/api/v1/super-admin/offices")
|
||||
@Get("/api/v1/super-admin/offices", [authHandler, roleHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
let query;
|
||||
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 : {
|
||||
name: {
|
||||
contains: filter,
|
||||
mode: "insensitive",
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const officesEntity: Offices[] = await this.officesService.get(query);
|
||||
const officesEntities: Offices[] = await this.officesService.get(query);
|
||||
//Hydrate ressource with prisma entity
|
||||
const offices = OfficeResource.map<OfficeResource>(OfficeResource, officesEntity, { strategy: "excludeAll" });
|
||||
const offices = OfficeResource.hydrateArray<OfficeResource>(officesEntities, { strategy: "excludeAll" });
|
||||
//success
|
||||
this.httpSuccess(response, offices);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @description Create a new office
|
||||
*/
|
||||
@Post("/api/v1/super-admin/offices")
|
||||
@Post("/api/v1/super-admin/offices", [authHandler, roleHandler, ruleHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init IUser resource with request body values
|
||||
@ -43,70 +62,82 @@ export default class OfficesController extends ApiController {
|
||||
//validate user
|
||||
await validateOrReject(officeEntity, { groups: ["createOffice"], forbidUnknownValues: false });
|
||||
//call service to get prisma entity
|
||||
const prismaEntityCreated = await this.officesService.create(officeEntity);
|
||||
const officeEntityCreated = await this.officesService.create(officeEntity);
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeEntityCreated = OfficeResource.hydrate<OfficeResource>(prismaEntityCreated, {
|
||||
const office = OfficeResource.hydrate<OfficeResource>(officeEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
//success
|
||||
this.httpSuccess(response, officeEntityCreated);
|
||||
this.httpCreated(response, office);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @description Modify a specific office by uid
|
||||
*/
|
||||
@Put("/api/v1/super-admin/offices/:uid")
|
||||
@Put("/api/v1/super-admin/offices/:uid", [authHandler, roleHandler, ruleHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const officeFound = await this.officesService.getByUid(uid);
|
||||
|
||||
if (!officeFound) {
|
||||
this.httpNotFoundRequest(response, "office not found");
|
||||
return;
|
||||
}
|
||||
//init IUser resource with request body values
|
||||
const officeEntity = OfficeResource.hydrate<OfficeResource>(req.body);
|
||||
//validate user
|
||||
await validateOrReject(officeEntity, { groups: ["update"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityUpdated = await this.officesService.update(uid, officeEntity);
|
||||
const officeEntityUpdated = await this.officesService.update(uid, officeEntity);
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeEntityUpdated = OfficeResource.hydrate<OfficeResource>(prismaEntityUpdated, {
|
||||
const office = OfficeResource.hydrate<OfficeResource>(officeEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
//success
|
||||
this.httpSuccess(response, officeEntityUpdated);
|
||||
this.httpSuccess(response, office);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @description Get a specific office by uid
|
||||
*/
|
||||
@Get("/api/v1/super-admin/offices/:uid")
|
||||
@Get("/api/v1/super-admin/offices/:uid", [authHandler, roleHandler, ruleHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
let officeEntity: Offices;
|
||||
//get query
|
||||
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
officeEntity = await this.officesService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
officeEntity = await this.officesService.getByUid(uid);
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
const officeEntity = await this.officesService.getByUid(uid, query);
|
||||
|
||||
if (!officeEntity) {
|
||||
this.httpNotFoundRequest(response, "office not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const office = OfficeResource.hydrate<OfficeResource>(officeEntity, { strategy: "excludeAll" });
|
||||
//success
|
||||
this.httpSuccess(response, office);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
148
src/app/api/super-admin/RolesController.ts
Normal file
148
src/app/api/super-admin/RolesController.ts
Normal file
@ -0,0 +1,148 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import RolesService from "@Services/super-admin/RolesService/RolesService";
|
||||
import { Service } from "typedi";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import { Role } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class RolesController extends ApiController {
|
||||
constructor(private rolesService: RolesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all roles
|
||||
*/
|
||||
@Get("/api/v1/super-admin/roles", [authHandler, roleHandler, ruleHandler])
|
||||
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 rolesEntities = await this.rolesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const roles = Role.hydrateArray<Role>(rolesEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, roles);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new role
|
||||
*/
|
||||
@Post("/api/v1/super-admin/roles", [authHandler, roleHandler, ruleHandler])
|
||||
protected async getAddresses(req: Request, response: Response) {
|
||||
try {
|
||||
//init IRole resource with request body values
|
||||
const roleEntity = Role.hydrate<Role>(req.body);
|
||||
|
||||
//validate role
|
||||
await validateOrReject(roleEntity, { groups: ["createRole"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const roleEntityCreated = await this.rolesService.create(roleEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const role = Role.hydrate<Role>(roleEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpCreated(response, role);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific role by uid
|
||||
*/
|
||||
@Put("/api/v1/super-admin/roles/:uid", [authHandler, roleHandler, ruleHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const roleFound = await this.rolesService.getByUid(uid);
|
||||
|
||||
if (!roleFound) {
|
||||
this.httpNotFoundRequest(response, "role not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init IRole resource with request body values
|
||||
const roleEntity = Role.hydrate<Role>(req.body);
|
||||
|
||||
//validate role
|
||||
await validateOrReject(roleEntity, { groups: ["updateRole"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const roleEntityUpdated = await this.rolesService.update(roleEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const role = Role.hydrate<Role>(roleEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, role);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific role by uid
|
||||
*/
|
||||
@Get("/api/v1/super-admin/roles/:uid", [authHandler, roleHandler, 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 roleEntity = await this.rolesService.getByUid(uid, query);
|
||||
|
||||
if (!roleEntity) {
|
||||
this.httpNotFoundRequest(response, "role not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const role = Role.hydrate<Role>(roleEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, role);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
144
src/app/api/super-admin/RulesController.ts
Normal file
144
src/app/api/super-admin/RulesController.ts
Normal file
@ -0,0 +1,144 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import RulesService from "@Services/super-admin/RulesService/RulesService";
|
||||
import { Service } from "typedi";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import { Rule } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class RulesController extends ApiController {
|
||||
constructor(private rulesService: RulesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all rules
|
||||
*/
|
||||
@Get("/api/v1/super-admin/rules", [authHandler, roleHandler, ruleHandler])
|
||||
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 rulesEntities = await this.rulesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const rules = Rule.hydrateArray<Rule>(rulesEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, rules);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new rule
|
||||
*/
|
||||
@Post("/api/v1/super-admin/rules", [authHandler, roleHandler, ruleHandler])
|
||||
protected async getAddresses(req: Request, response: Response) {
|
||||
try {
|
||||
//init IRule resource with request body values
|
||||
const ruleEntity = Rule.hydrate<Rule>(req.body);
|
||||
|
||||
//validate rule
|
||||
await validateOrReject(ruleEntity, { groups: ["createRule"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const ruleEntityCreated = await this.rulesService.create(ruleEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const rule = Rule.hydrate<Rule>(ruleEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpCreated(response, rule);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific rule by uid
|
||||
*/
|
||||
@Put("/api/v1/super-admin/rules/:uid", [authHandler, roleHandler, ruleHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const ruleFound = await this.rulesService.getByUid(uid);
|
||||
|
||||
if (!ruleFound) {
|
||||
this.httpNotFoundRequest(response, "rule not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init IRule resource with request body values
|
||||
const ruleEntity = Rule.hydrate<Rule>(req.body);
|
||||
|
||||
//call service to get prisma entity
|
||||
const ruleEntityUpdated = await this.rulesService.update(ruleEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const rule = Rule.hydrate<Rule>(ruleEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, rule);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific rule by uid
|
||||
*/
|
||||
@Get("/api/v1/super-admin/rules/:uid", [authHandler, roleHandler, 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 ruleEntity = await this.rulesService.getByUid(uid, query);
|
||||
|
||||
if (!ruleEntity) {
|
||||
this.httpNotFoundRequest(response, "rule not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const rule = Rule.hydrate<Rule>(ruleEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, rule);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@ -4,35 +4,56 @@ import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import UsersService from "@Services/super-admin/UsersService/UsersService";
|
||||
import { Service } from "typedi";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import User from "le-coffre-resources/dist/Notary";
|
||||
import { Users } from "@prisma/client";
|
||||
import User from "le-coffre-resources/dist/SuperAdmin";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
import RolesService from "@Services/super-admin/RolesService/RolesService";
|
||||
import OfficeRolesService from "@Services/super-admin/OfficeRolesService/OfficeRolesService";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class UsersController extends ApiController {
|
||||
constructor(private usersService: UsersService) {
|
||||
constructor(private usersService: UsersService, private roleService: RolesService, private officeRoleService: OfficeRolesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all users
|
||||
*/
|
||||
@Get("/api/v1/super-admin/users")
|
||||
@Get("/api/v1/super-admin/users", [authHandler, roleHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
let query;
|
||||
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: {
|
||||
contact: {
|
||||
OR: [
|
||||
{ first_name: { contains: filter, mode: "insensitive" } },
|
||||
{ last_name: { contains: filter, mode: "insensitive" } },
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const usersEntity = await this.usersService.get(query);
|
||||
const usersEntities = await this.usersService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const users = User.map<User>(User, usersEntity, { strategy: "excludeAll" });
|
||||
const users = User.hydrateArray<User>(usersEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, users);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -40,8 +61,8 @@ export default class UsersController extends ApiController {
|
||||
/**
|
||||
* @description Create a new user
|
||||
*/
|
||||
@Post("/api/v1/super-admin/users")
|
||||
protected async getAddresses(req: Request, response: Response) {
|
||||
@Post("/api/v1/super-admin/users", [authHandler, roleHandler, ruleHandler])
|
||||
protected async create(req: Request, response: Response) {
|
||||
try {
|
||||
//init IUser resource with request body values
|
||||
const userEntity = User.hydrate<User>(req.body);
|
||||
@ -50,17 +71,17 @@ export default class UsersController extends ApiController {
|
||||
await validateOrReject(userEntity, { groups: ["createUser"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityCreated = await this.usersService.create(userEntity);
|
||||
const userEntityCreated = await this.usersService.create(userEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const userEntityCreated = User.hydrate<User>(prismaEntityCreated, {
|
||||
const user = User.hydrate<User>(userEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, userEntityCreated);
|
||||
this.httpCreated(response, user);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -68,31 +89,62 @@ export default class UsersController extends ApiController {
|
||||
/**
|
||||
* @description Modify a specific user by uid
|
||||
*/
|
||||
@Put("/api/v1/super-admin/users/:uid")
|
||||
@Put("/api/v1/super-admin/users/:uid", [authHandler, roleHandler, ruleHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const userFound = await this.usersService.getByUidWithRole(uid);
|
||||
|
||||
if (!userFound) {
|
||||
this.httpNotFoundRequest(response, "user not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init IUser resource with request body values
|
||||
const userEntity = User.hydrate<User>(req.body);
|
||||
|
||||
//validate user
|
||||
await validateOrReject(userEntity, { groups: ["update"] });
|
||||
if(userEntity.role) {
|
||||
const role = await this.roleService.getByUid(userEntity.role.uid!);
|
||||
if(!role) {
|
||||
this.httpBadRequest(response, "Role not found");
|
||||
return;
|
||||
}
|
||||
if (role.name === "super-admin" || userFound.role.name === "super-admin" ) {
|
||||
this.httpBadRequest(response, "Cannot assign or remove super-admin role");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(userEntity.office_role) {
|
||||
const officeRole = await this.officeRoleService.getByUid(userEntity.office_role.uid!);
|
||||
if(!officeRole) {
|
||||
this.httpBadRequest(response, "Office role not found");
|
||||
return;
|
||||
}
|
||||
if (officeRole.office_uid != userFound.office_uid) {
|
||||
this.httpBadRequest(response, "Cannot assign an office role from another office");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityUpdated = await this.usersService.update(uid, userEntity);
|
||||
const userEntityUpdated = await this.usersService.update(uid, userEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const userEntityUpdated = User.hydrate<User>(prismaEntityUpdated, {
|
||||
const user = User.hydrate<User>(userEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, userEntityUpdated);
|
||||
this.httpSuccess(response, user);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -100,21 +152,23 @@ export default class UsersController extends ApiController {
|
||||
/**
|
||||
* @description Get a specific user by uid
|
||||
*/
|
||||
@Get("/api/v1/super-admin/users/:uid")
|
||||
@Get("/api/v1/super-admin/users/:uid", [authHandler, roleHandler, ruleHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
let userEntity: Users;
|
||||
//get query
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
userEntity = await this.usersService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
userEntity = await this.usersService.getByUid(uid);
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
const userEntity = await this.usersService.getByUid(uid, query);
|
||||
|
||||
if (!userEntity) {
|
||||
this.httpNotFoundRequest(response, "user not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
@ -123,7 +177,7 @@ export default class UsersController extends ApiController {
|
||||
//success
|
||||
this.httpSuccess(response, user);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
116
src/app/api/super-admin/VotesController.ts
Normal file
116
src/app/api/super-admin/VotesController.ts
Normal file
@ -0,0 +1,116 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import VotesService from "@Services/super-admin/VotesService/VotesService";
|
||||
import { Service } from "typedi";
|
||||
import { Vote } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import { Votes } from "@prisma/client";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class VotesController extends ApiController {
|
||||
constructor(private votesService: VotesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all votes
|
||||
*/
|
||||
@Get("/api/v1/super-admin/votes", [authHandler, roleHandler])
|
||||
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 votesEntities = await this.votesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const votes = Vote.hydrateArray<Vote>(votesEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, votes);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific vote by uid
|
||||
*/
|
||||
@Get("/api/v1/super-admin/votes/:uid", [authHandler, roleHandler])
|
||||
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 voteEntity = await this.votesService.getByUid(uid, query);
|
||||
|
||||
if (!voteEntity) {
|
||||
this.httpNotFoundRequest(response, "vote not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const vote = Vote.hydrate<Vote>(voteEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, vote);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a specific vote
|
||||
*/
|
||||
@Delete("/api/v1/super-admin/votes/:uid", [authHandler, roleHandler])
|
||||
protected async delete(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const voteFound = await this.votesService.getByUid(uid);
|
||||
|
||||
if (!voteFound) {
|
||||
this.httpNotFoundRequest(response, "vote not found");
|
||||
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
|
||||
const votetEntity: Votes = await this.votesService.delete(uid);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const vote = Vote.hydrate<Vote>(votetEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, vote);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
109
src/app/index.ts
109
src/app/index.ts
@ -1,16 +1,50 @@
|
||||
import { Container } from "typedi";
|
||||
import HomeController from "./HomeController";
|
||||
import UsersController from "./api/super-admin/UsersController";
|
||||
import FoldersController from "./api/super-admin/OfficeFoldersController";
|
||||
import CustomersController from "./api/super-admin/CustomersController";
|
||||
import OfficesController from "./api/super-admin/OfficesController";
|
||||
import DeedsController from "./api/super-admin/DeedsController";
|
||||
import DeedTypesController from "./api/super-admin/DeedTypesController";
|
||||
import DocumentsController from "./api/super-admin/DocumentsController";
|
||||
import DocumentTypesController from "./api/super-admin/DocumentTypesController";
|
||||
import IdNotUserInfoController from "./api/idnot-user/UserInfoController";
|
||||
import UsersControllerSuperAdmin from "./api/super-admin/UsersController";
|
||||
import FoldersControllerSuperAdmin from "./api/super-admin/OfficeFoldersController";
|
||||
import CustomersControllerSuperAdmin from "./api/super-admin/CustomersController";
|
||||
import OfficesControllerSuperAdmin from "./api/super-admin/OfficesController";
|
||||
import DeedsControllerSuperAdmin from "./api/super-admin/DeedsController";
|
||||
import DeedTypesControllerSuperAdmin from "./api/super-admin/DeedTypesController";
|
||||
import DocumentsControllerSuperAdmin from "./api/super-admin/DocumentsController";
|
||||
import DocumentTypesControllerSuperAdmin from "./api/super-admin/DocumentTypesController";
|
||||
import IdNotUserController from "./api/idnot/UserController";
|
||||
import FranceConnectCustomerController from "./api/franceConnect/CustomerController";
|
||||
import FilesControllerSuperAdmin from "./api/super-admin/FilesController";
|
||||
import RulesControllerSuperAdmin from "./api/super-admin/RulesController";
|
||||
import RolesControllerSuperAdmin from "./api/super-admin/RolesController";
|
||||
import OfficeRolesControllerSuperAdmin from "./api/super-admin/OfficeRolesController";
|
||||
import UsersControllerAdmin from "./api/admin/UsersController";
|
||||
import FoldersControllerAdmin from "./api/admin/OfficeFoldersController";
|
||||
import CustomersControllerAdmin from "./api/admin/CustomersController";
|
||||
import OfficesControllerAdmin from "./api/admin/OfficesController";
|
||||
import DeedsControllerAdmin from "./api/admin/DeedsController";
|
||||
import DeedTypesControllerAdmin from "./api/admin/DeedTypesController";
|
||||
import DocumentsControllerAdmin from "./api/admin/DocumentsController";
|
||||
import DocumentTypesControllerAdmin from "./api/admin/DocumentTypesController";
|
||||
import FilesControllerAdmin from "./api/admin/FilesController";
|
||||
import RulesControllerAdmin from "./api/admin/RulesController";
|
||||
import RolesControllerAdmin from "./api/admin/RolesController";
|
||||
import OfficeRolesControllerAdmin from "./api/admin/OfficeRolesController";
|
||||
import UsersControllerNotary from "./api/notary/UsersController";
|
||||
import FoldersControllerNotary from "./api/notary/OfficeFoldersController";
|
||||
import CustomersControllerNotary from "./api/notary/CustomersController";
|
||||
import OfficesControllerNotary from "./api/notary/OfficesController";
|
||||
import DeedsControllerNotary from "./api/notary/DeedsController";
|
||||
import DeedTypesControllerNotary from "./api/notary/DeedTypesController";
|
||||
import DocumentsControllerNotary from "./api/notary/DocumentsController";
|
||||
import DocumentTypesControllerNotary from "./api/notary/DocumentTypesController";
|
||||
import FilesControllerNotary from "./api/notary/FilesController";
|
||||
import RulesControllerNotary from "./api/notary/RulesController";
|
||||
import RolesControllerNotary from "./api/notary/RolesController";
|
||||
import OfficeRolesControllerNotary from "./api/notary/OfficeRolesController";
|
||||
import FilesControllerCustomer from "./api/customer/FilesController";
|
||||
import DocumentsControllerCustomer from "./api/customer/DocumentsController";
|
||||
import FilesController from "./api/super-admin/FilesController";
|
||||
import OfficeFoldersController from "./api/customer/OfficeFoldersController";
|
||||
import CustomersController from "./api/customer/CustomersController";
|
||||
import AppointmentsController from "./api/super-admin/AppointmentsController";
|
||||
import VotesController from "./api/super-admin/VotesController";
|
||||
import LiveVoteController from "./api/super-admin/LiveVoteController";
|
||||
|
||||
|
||||
/**
|
||||
@ -19,16 +53,51 @@ import FilesController from "./api/super-admin/FilesController";
|
||||
export default {
|
||||
start: () => {
|
||||
Container.get(HomeController);
|
||||
Container.get(UsersController);
|
||||
Container.get(FoldersController);
|
||||
Container.get(CustomersController);
|
||||
Container.get(OfficesController);
|
||||
Container.get(DeedsController);
|
||||
Container.get(DeedTypesController);
|
||||
Container.get(DocumentsController);
|
||||
Container.get(DocumentTypesController);
|
||||
Container.get(IdNotUserInfoController);
|
||||
Container.get(FilesController);
|
||||
Container.get(UsersControllerSuperAdmin);
|
||||
Container.get(FoldersControllerSuperAdmin);
|
||||
Container.get(CustomersControllerSuperAdmin);
|
||||
Container.get(OfficesControllerSuperAdmin);
|
||||
Container.get(DeedsControllerSuperAdmin);
|
||||
Container.get(DeedTypesControllerSuperAdmin);
|
||||
Container.get(DocumentsControllerSuperAdmin);
|
||||
Container.get(DocumentTypesControllerSuperAdmin);
|
||||
Container.get(AppointmentsController);
|
||||
Container.get(VotesController);
|
||||
Container.get(LiveVoteController);
|
||||
Container.get(IdNotUserController);
|
||||
Container.get(FranceConnectCustomerController);
|
||||
Container.get(FilesControllerSuperAdmin);
|
||||
Container.get(DocumentsControllerSuperAdmin);
|
||||
Container.get(RulesControllerSuperAdmin);
|
||||
Container.get(RolesControllerSuperAdmin);
|
||||
Container.get(OfficeRolesControllerSuperAdmin);
|
||||
Container.get(UsersControllerAdmin);
|
||||
Container.get(FoldersControllerAdmin);
|
||||
Container.get(CustomersControllerAdmin);
|
||||
Container.get(OfficesControllerAdmin);
|
||||
Container.get(DeedsControllerAdmin);
|
||||
Container.get(DeedTypesControllerAdmin);
|
||||
Container.get(DocumentsControllerAdmin);
|
||||
Container.get(DocumentTypesControllerAdmin);
|
||||
Container.get(FilesControllerAdmin);
|
||||
Container.get(RulesControllerAdmin);
|
||||
Container.get(RolesControllerAdmin);
|
||||
Container.get(OfficeRolesControllerAdmin);
|
||||
Container.get(UsersControllerNotary);
|
||||
Container.get(FoldersControllerNotary);
|
||||
Container.get(CustomersControllerNotary);
|
||||
Container.get(OfficesControllerNotary);
|
||||
Container.get(DeedsControllerNotary);
|
||||
Container.get(DeedTypesControllerNotary);
|
||||
Container.get(DocumentsControllerNotary);
|
||||
Container.get(DocumentTypesControllerNotary);
|
||||
Container.get(FilesControllerNotary);
|
||||
Container.get(RulesControllerNotary);
|
||||
Container.get(RolesControllerNotary);
|
||||
Container.get(OfficeRolesControllerNotary);
|
||||
Container.get(FilesControllerCustomer);
|
||||
Container.get(DocumentsControllerCustomer);
|
||||
Container.get(OfficeFoldersController);
|
||||
Container.get(CustomersController)
|
||||
},
|
||||
};
|
||||
|
31
src/app/middlewares/AuthHandler.ts
Normal file
31
src/app/middlewares/AuthHandler.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import HttpCodes from "@Common/system/controller-pattern/HttpCodes";
|
||||
import AuthService from "@Services/common/AuthService/AuthService";
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import Container from "typedi";
|
||||
|
||||
export default function authHandler(req: Request, response: Response, next: NextFunction) {
|
||||
try {
|
||||
const authHeader = req.headers["authorization"];
|
||||
const token = authHeader && authHeader.split(" ")[1];
|
||||
|
||||
if (!token) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Missing token in authorization header");
|
||||
return;
|
||||
}
|
||||
|
||||
const authService = Container.get(AuthService);
|
||||
authService.verifyAccessToken(token, (err, userPayload) => {
|
||||
if (err) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Error while verifying token");
|
||||
return;
|
||||
}
|
||||
req.body.user = userPayload;
|
||||
next();
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
}
|
31
src/app/middlewares/CustomerHandler/DocumentHandler.ts
Normal file
31
src/app/middlewares/CustomerHandler/DocumentHandler.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import HttpCodes from "@Common/system/controller-pattern/HttpCodes";
|
||||
import DocumentsService from "@Services/customer/DocumentsService/DocumentsService";
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import Container from "typedi";
|
||||
|
||||
export default async function documentHandler(req: Request, response: Response, next: NextFunction) {
|
||||
try {
|
||||
const customerId = req.body.user.customerId;
|
||||
const uid = req.path && req.path.split("/")[5];
|
||||
|
||||
if (!uid) {
|
||||
response.status(HttpCodes.BAD_REQUEST).send("Missing document uid");
|
||||
return;
|
||||
}
|
||||
|
||||
const documentService = Container.get(DocumentsService);
|
||||
const document = await documentService.getByUid(uid);
|
||||
|
||||
if (document?.depositor_uid != customerId) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this depositor");
|
||||
return;
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
}
|
39
src/app/middlewares/CustomerHandler/FileHandler.ts
Normal file
39
src/app/middlewares/CustomerHandler/FileHandler.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import HttpCodes from "@Common/system/controller-pattern/HttpCodes";
|
||||
import FilesService from "@Services/common/FilesService/FilesService";
|
||||
import DocumentsService from "@Services/customer/DocumentsService/DocumentsService";
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import Container from "typedi";
|
||||
|
||||
export default async function fileHandler(req: Request, response: Response, next: NextFunction) {
|
||||
const customerId = req.body.user.customerId;
|
||||
const uid = req.path && req.path.split("/")[5];
|
||||
const document = req.body.document;
|
||||
|
||||
if (uid) {
|
||||
const fileService = Container.get(FilesService);
|
||||
const file = await fileService.getByUidWithDocument(uid);
|
||||
if (!file) {
|
||||
response.status(HttpCodes.NOT_FOUND).send("File not found");
|
||||
return;
|
||||
}
|
||||
if (file.document.depositor_uid != customerId) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this depositor");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (document) {
|
||||
const documentService = Container.get(DocumentsService);
|
||||
const documentFound = await documentService.getByUid(document.uid!);
|
||||
if(!documentFound) {
|
||||
response.status(HttpCodes.NOT_FOUND).send("Document not found");
|
||||
return;
|
||||
}
|
||||
if (documentFound.depositor_uid != customerId) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this depositor");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import multer from "multer";
|
||||
|
||||
export default function fileHandler(req: Request, response: Response, next: NextFunction) {
|
||||
const storage = multer.memoryStorage()
|
||||
const upload = multer({storage:storage}).single('file');
|
||||
|
||||
// Here call the upload middleware of multer
|
||||
upload(req, response, function (err) {
|
||||
if (err instanceof multer.MulterError) {
|
||||
// A Multer error occurred when uploading.
|
||||
const err = new Error('Multer error');
|
||||
return next(err)
|
||||
} else if (err) {
|
||||
// An unknown error occurred when uploading.
|
||||
const err = new Error('Server Error')
|
||||
return next(err)
|
||||
}
|
||||
next()
|
||||
})
|
||||
}
|
||||
|
51
src/app/middlewares/OfficeMembershipHandlers/DeedHandler.ts
Normal file
51
src/app/middlewares/OfficeMembershipHandlers/DeedHandler.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import HttpCodes from "@Common/system/controller-pattern/HttpCodes";
|
||||
import DeedsService from "@Services/super-admin/DeedsService/DeedsService";
|
||||
import { DocumentType } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import Container from "typedi";
|
||||
import DocumentTypesService from "@Services/super-admin/DocumentTypesService/DocumentTypesService";
|
||||
|
||||
export default async function deedHandler(req: Request, response: Response, next: NextFunction) {
|
||||
try {
|
||||
const officeId = req.body.user.office_Id;
|
||||
const uid = req.path && req.path.split("/")[5];
|
||||
const documentTypes: DocumentType[] = req.body.document_types;
|
||||
|
||||
if (uid) {
|
||||
const deedService = Container.get(DeedsService);
|
||||
const deed = await deedService.getByUidWithOffice(uid);
|
||||
|
||||
if (!deed) {
|
||||
response.status(HttpCodes.NOT_FOUND).send("Deed not found");
|
||||
return;
|
||||
}
|
||||
|
||||
if (deed.deed_type.office.uid != officeId) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (documentTypes) {
|
||||
const documentTypeService = Container.get(DocumentTypesService);
|
||||
documentTypes.forEach(async (documentType) => {
|
||||
const deedTypeWithOffice = await documentTypeService.getByUidWithOffice(documentType.uid!);
|
||||
if (!deedTypeWithOffice) {
|
||||
response.status(HttpCodes.NOT_FOUND).send("Deed type not found");
|
||||
return;
|
||||
}
|
||||
if (deedTypeWithOffice.office?.uid != officeId) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
import HttpCodes from "@Common/system/controller-pattern/HttpCodes";
|
||||
import DeedTypesService from "@Services/super-admin/DeedTypesService/DeedTypesService";
|
||||
import { DocumentType } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import Container from "typedi";
|
||||
import DocumentTypesService from "@Services/super-admin/DocumentTypesService/DocumentTypesService";
|
||||
|
||||
export default async function deedTypeHandler(req: Request, response: Response, next: NextFunction) {
|
||||
try {
|
||||
const officeId = req.body.user.office_Id;
|
||||
const uid = req.path && req.path.split("/")[5];
|
||||
const documentTypes: DocumentType[] = req.body.document_types;
|
||||
const office = req.body.office;
|
||||
|
||||
if (office && office.uid != officeId) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||
return;
|
||||
}
|
||||
|
||||
if (uid) {
|
||||
const deedTypeService = Container.get(DeedTypesService);
|
||||
const deedType = await deedTypeService.getByUidWithOffice(uid!);
|
||||
|
||||
if (!deedType) {
|
||||
response.status(HttpCodes.NOT_FOUND).send("Deed type not found");
|
||||
return;
|
||||
}
|
||||
|
||||
if (deedType.office.uid != officeId) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (documentTypes) {
|
||||
const documentTypeService = Container.get(DocumentTypesService);
|
||||
documentTypes.forEach(async (documentType) => {
|
||||
const documentTypeWithOffice = await documentTypeService.getByUidWithOffice(documentType.uid!);
|
||||
if (!documentTypeWithOffice) {
|
||||
response.status(HttpCodes.NOT_FOUND).send("Document type not found");
|
||||
return;
|
||||
}
|
||||
if (documentTypeWithOffice.office?.uid != officeId) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
next();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
import HttpCodes from "@Common/system/controller-pattern/HttpCodes";
|
||||
import { DocumentType } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import Container from "typedi";
|
||||
import { OfficeFolder } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
|
||||
import DocumentTypesService from "@Services/super-admin/DocumentTypesService/DocumentTypesService";
|
||||
import OfficeFoldersService from "@Services/super-admin/OfficeFoldersService/OfficeFoldersService";
|
||||
|
||||
export default async function documentHandler(req: Request, response: Response, next: NextFunction) {
|
||||
try {
|
||||
const officeId = req.body.user.office_Id;
|
||||
const uid = req.path && req.path.split("/")[5];
|
||||
const documentType: DocumentType = req.body.document_type;
|
||||
const folder: OfficeFolder = req.body.folder;
|
||||
|
||||
if (folder) {
|
||||
const officeFolderService = Container.get(OfficeFoldersService);
|
||||
const officeFolderWithOffice = await officeFolderService.getByUidWithOffice(folder.uid!);
|
||||
if (!officeFolderWithOffice) {
|
||||
response.status(HttpCodes.NOT_FOUND).send("Folder not found");
|
||||
return;
|
||||
}
|
||||
if (officeFolderWithOffice.office?.uid != officeId) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (documentType) {
|
||||
const documentTypeService = Container.get(DocumentTypesService);
|
||||
const documentTypeWithOffice = await documentTypeService.getByUidWithOffice(documentType.uid!);
|
||||
if (!documentTypeWithOffice) {
|
||||
response.status(HttpCodes.NOT_FOUND).send("Document type not found");
|
||||
return;
|
||||
}
|
||||
if (documentTypeWithOffice.office?.uid != officeId) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (uid) {
|
||||
const documentService = Container.get(DocumentsService);
|
||||
const document = await documentService.getByUidWithOffice(uid!);
|
||||
|
||||
if (!document) {
|
||||
response.sendStatus(HttpCodes.NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
|
||||
if (document.document_type.office.uid != officeId) {
|
||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
import HttpCodes from "@Common/system/controller-pattern/HttpCodes";
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import Container from "typedi";
|
||||
import DocumentTypesService from "@Services/super-admin/DocumentTypesService/DocumentTypesService";
|
||||
|
||||
export default async function documentTypeHandler(req: Request, response: Response, next: NextFunction) {
|
||||
try {
|
||||
const officeId = req.body.user.office_Id;
|
||||
const uid = req.path && req.path.split("/")[5];
|
||||
const office = req.body.office;
|
||||
|
||||
if (office && office.uid != officeId) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||
return;
|
||||
}
|
||||
|
||||
if (uid) {
|
||||
const documentTypeService = Container.get(DocumentTypesService);
|
||||
const documentType = await documentTypeService.getByUidWithOffice(uid!);
|
||||
|
||||
if (!documentType) {
|
||||
response.status(HttpCodes.NOT_FOUND).send("Document type not found");
|
||||
return;
|
||||
}
|
||||
|
||||
if (documentType.office.uid != officeId) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
}
|
48
src/app/middlewares/OfficeMembershipHandlers/FileHandler.ts
Normal file
48
src/app/middlewares/OfficeMembershipHandlers/FileHandler.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import HttpCodes from "@Common/system/controller-pattern/HttpCodes";
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import Container from "typedi";
|
||||
import FilesService from "@Services/common/FilesService/FilesService";
|
||||
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
|
||||
|
||||
export default async function fileHandler(req: Request, response: Response, next: NextFunction) {
|
||||
try {
|
||||
const officeId = req.body.user.office_Id;
|
||||
let uid = req.path && req.path.split("/")[5];
|
||||
const document = req.body.document;
|
||||
|
||||
if (document) {
|
||||
const documentService = Container.get(DocumentsService);
|
||||
const documentWithOffice = await documentService.getByUidWithOffice(document.uid!);
|
||||
if (!documentWithOffice) {
|
||||
response.status(HttpCodes.NOT_FOUND).send("Document not found");
|
||||
return;
|
||||
}
|
||||
if (documentWithOffice.folder.office?.uid != officeId) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (uid === "download") uid = req.path && req.path.split("/")[6];
|
||||
|
||||
if (uid) {
|
||||
const fileService = Container.get(FilesService);
|
||||
const file = await fileService.getByUidWithOffice(uid!);
|
||||
|
||||
if (!file) {
|
||||
response.status(HttpCodes.NOT_FOUND).send("File not found");
|
||||
return;
|
||||
}
|
||||
if (file.document.folder.office.uid != officeId) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
import HttpCodes from "@Common/system/controller-pattern/HttpCodes";
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import Container from "typedi";
|
||||
import OfficeFoldersService from "@Services/super-admin/OfficeFoldersService/OfficeFoldersService";
|
||||
import DeedTypesService from "@Services/super-admin/DeedTypesService/DeedTypesService";
|
||||
|
||||
export default async function folderHandler(req: Request, response: Response, next: NextFunction) {
|
||||
try {
|
||||
const officeId = req.body.user.office_Id;
|
||||
const uid = req.path && req.path.split("/")[5];
|
||||
const office = req.body.office;
|
||||
const officeFolderNumber = req.body.folder_number;
|
||||
const deed = req.body.deed;
|
||||
|
||||
if (office && office.uid != officeId) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||
return;
|
||||
}
|
||||
|
||||
if (deed && deed.deed_type) {
|
||||
const deedTypeService = Container.get(DeedTypesService);
|
||||
const deedTypeWithOffice = await deedTypeService.getByUidWithOffice(deed.deed_type.uid!);
|
||||
if (!deedTypeWithOffice) {
|
||||
response.status(HttpCodes.NOT_FOUND).send("Deed type not found");
|
||||
return;
|
||||
}
|
||||
if (deedTypeWithOffice.office.uid != officeId) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this deed type");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const officeFolderService = Container.get(OfficeFoldersService);
|
||||
|
||||
if (officeFolderNumber && req.method == "POST") {
|
||||
const officeFoldersWithSameNumber = await officeFolderService.get({
|
||||
where: { folder_number: officeFolderNumber, office: { uid: officeId } },
|
||||
});
|
||||
if (officeFoldersWithSameNumber.length) {
|
||||
response.status(HttpCodes.BAD_REQUEST).send("Office number already used");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (uid) {
|
||||
const officeFolder = await officeFolderService.getByUidWithOffice(uid!);
|
||||
|
||||
if (!officeFolder) {
|
||||
response.status(HttpCodes.NOT_FOUND).send("Office folder not found");
|
||||
return;
|
||||
}
|
||||
|
||||
if (officeFolder.office.uid != officeId) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
import HttpCodes from "@Common/system/controller-pattern/HttpCodes";
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import Container from "typedi";
|
||||
import OfficeRolesService from "@Services/super-admin/OfficeRolesService/OfficeRolesService";
|
||||
|
||||
export default async function officeRoleHandler(req: Request, response: Response, next: NextFunction) {
|
||||
try {
|
||||
const officeId = req.body.user.office_Id;
|
||||
const uid = req.path && req.path.split("/")[5];
|
||||
const office = req.body.office;
|
||||
|
||||
if (office && office.uid != officeId) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||
return;
|
||||
}
|
||||
|
||||
if (uid) {
|
||||
const officeRoleService = Container.get(OfficeRolesService);
|
||||
const officeRole = await officeRoleService.getByUidWithOffice(uid!);
|
||||
|
||||
if (!officeRole) {
|
||||
response.status(HttpCodes.NOT_FOUND).send("Office role not found");
|
||||
return;
|
||||
}
|
||||
|
||||
if (officeRole.office.uid != officeId) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
}
|
38
src/app/middlewares/OfficeMembershipHandlers/UserHandler.ts
Normal file
38
src/app/middlewares/OfficeMembershipHandlers/UserHandler.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import HttpCodes from "@Common/system/controller-pattern/HttpCodes";
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import Container from "typedi";
|
||||
import UsersService from "@Services/super-admin/UsersService/UsersService";
|
||||
|
||||
export default async function userHandler(req: Request, response: Response, next: NextFunction) {
|
||||
try {
|
||||
const officeId = req.body.user.office_Id;
|
||||
const uid = req.path && req.path.split("/")[5];
|
||||
const office = req.body.office_membership;
|
||||
|
||||
if (office && office.uid != officeId) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||
return;
|
||||
}
|
||||
|
||||
if (uid) {
|
||||
const userService = Container.get(UsersService);
|
||||
const user = await userService.getByUidWithOffice(uid!);
|
||||
|
||||
if (!user) {
|
||||
response.status(HttpCodes.NOT_FOUND).send("User not found");
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.office_membership.uid != officeId) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
}
|
22
src/app/middlewares/RolesHandler.ts
Normal file
22
src/app/middlewares/RolesHandler.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import HttpCodes from "@Common/system/controller-pattern/HttpCodes";
|
||||
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;
|
||||
|
||||
if (namespace != "notary" && role != namespace && role != "super-admin") {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this role");
|
||||
return;
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
}
|
21
src/app/middlewares/RulesHandler.ts
Normal file
21
src/app/middlewares/RulesHandler.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import HttpCodes from "@Common/system/controller-pattern/HttpCodes";
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
|
||||
export default async function ruleHandler(req: Request, response: Response, next: NextFunction) {
|
||||
try {
|
||||
const rules = req.body.user.rules;
|
||||
const service = req.path && req.path.split("/")[4];
|
||||
|
||||
if (!rules.includes(req.method + " " + service)) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with those rules");
|
||||
return;
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
}
|
@ -19,6 +19,9 @@ export class BackendVariables {
|
||||
@IsNotEmpty()
|
||||
public readonly DATABASE_NAME!: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
public readonly DATABASE_URL!: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
public readonly API_ROOT_URL!: string;
|
||||
|
||||
@ -31,8 +34,6 @@ export class BackendVariables {
|
||||
@IsNotEmpty()
|
||||
public readonly APP_ROOT_URL!: string;
|
||||
|
||||
public readonly NODE_ENV = process.env.NODE_ENV;
|
||||
|
||||
@IsNotEmpty()
|
||||
public readonly IDNOT_CONNEXION_URL!: string;
|
||||
|
||||
@ -54,13 +55,27 @@ export class BackendVariables {
|
||||
@IsNotEmpty()
|
||||
public readonly PINATA_GATEWAY!: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
public readonly ACCESS_TOKEN_SECRET!: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
public readonly REFRESH_TOKEN_SECRET!: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
public readonly MAILCHIMP_API_KEY!: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
public readonly ENV!: string;
|
||||
|
||||
public constructor() {
|
||||
|
||||
dotenv.config();
|
||||
this.DATABASE_PORT = process.env["DATABASE_PORT"]!;
|
||||
this.DATABASE_HOST = process.env["DATABASE_HOST"]!;
|
||||
this.DATABASE_USERNAME = process.env["DATABASE_USERNAME"]!;
|
||||
this.DATABASE_PASSWORD = process.env["DATABASE_PASSWORD"]!;
|
||||
this.DATABASE_NAME = process.env["DATABASE_NAME"]!;
|
||||
this.DATABASE_URL = process.env["DEV_PRISMA_STUDIO_DB_URL"]!;
|
||||
this.API_ROOT_URL = process.env["API_ROOT_URL"]!;
|
||||
this.APP_PORT = process.env["APP_PORT"]!;
|
||||
this.APP_ROOT_URL = process.env["APP_ROOT_URL"]!;
|
||||
@ -72,9 +87,23 @@ export class BackendVariables {
|
||||
this.PINATA_API_KEY = process.env["PINATA_API_KEY"]!;
|
||||
this.PINATA_API_SECRET = process.env["PINATA_API_SECRET"]!;
|
||||
this.PINATA_GATEWAY = process.env["PINATA_GATEWAY"]!;
|
||||
this.ACCESS_TOKEN_SECRET = process.env["ACCESS_TOKEN_SECRET"]!;
|
||||
this.REFRESH_TOKEN_SECRET = process.env["REFRESH_TOKEN_SECRET"]!;
|
||||
this.MAILCHIMP_API_KEY = process.env["MAILCHIMP_API_KEY"]!;
|
||||
this.ENV = process.env["ENV"]!;
|
||||
|
||||
}
|
||||
public async validate(groups?: string[]) {
|
||||
const validationOptions = groups ? { groups } : undefined;
|
||||
|
||||
try {
|
||||
await validateOrReject(this, validationOptions);
|
||||
} catch (error: any) {
|
||||
if (process.env["ENV"] === "dev") {
|
||||
throw error;
|
||||
}
|
||||
throw new Error("Some env variables are required!");
|
||||
}
|
||||
public async validate() {
|
||||
await validateOrReject(this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- Added the required column `iv` to the `files` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "files" ADD COLUMN "iv" VARCHAR(255) NOT NULL;
|
@ -1,8 +0,0 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- Added the required column `file_name` to the `files` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "files" ADD COLUMN "file_name" VARCHAR(255) NOT NULL;
|
@ -1,9 +0,0 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `iv` on the `files` table. All the data in the column will be lost.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "files" DROP COLUMN "iv",
|
||||
ADD COLUMN "key" VARCHAR(255);
|
@ -1,2 +0,0 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "files" ADD COLUMN "archived_at" TIMESTAMP(3);
|
@ -35,9 +35,9 @@ CREATE TABLE "contacts" (
|
||||
"last_name" VARCHAR(255) NOT NULL,
|
||||
"email" VARCHAR(255) NOT NULL,
|
||||
"phone_number" VARCHAR(50),
|
||||
"cell_phone_number" VARCHAR(50),
|
||||
"cell_phone_number" VARCHAR(50) NOT NULL,
|
||||
"civility" "ECivility" NOT NULL DEFAULT 'MALE',
|
||||
"address_uid" VARCHAR(255) NOT NULL,
|
||||
"address_uid" VARCHAR(255),
|
||||
"birthdate" TIMESTAMP(3),
|
||||
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3),
|
||||
@ -50,6 +50,7 @@ CREATE TABLE "users" (
|
||||
"uid" TEXT NOT NULL,
|
||||
"idNot" VARCHAR(255) NOT NULL,
|
||||
"contact_uid" VARCHAR(255) NOT NULL,
|
||||
"roles_uid" TEXT NOT NULL,
|
||||
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3),
|
||||
"office_uid" VARCHAR(255) NOT NULL,
|
||||
@ -174,6 +175,11 @@ CREATE TABLE "files" (
|
||||
"uid" TEXT NOT NULL,
|
||||
"document_uid" VARCHAR(255) NOT NULL,
|
||||
"file_path" VARCHAR(255) NOT NULL,
|
||||
"file_name" VARCHAR(255) NOT NULL,
|
||||
"mimetype" VARCHAR(255) NOT NULL,
|
||||
"size" INTEGER NOT NULL,
|
||||
"archived_at" TIMESTAMP(3),
|
||||
"key" VARCHAR(255),
|
||||
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3),
|
||||
|
||||
@ -249,6 +255,50 @@ CREATE TABLE "deed_type_has_document_types" (
|
||||
CONSTRAINT "deed_type_has_document_types_pkey" PRIMARY KEY ("uid")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "roles" (
|
||||
"uid" TEXT NOT NULL,
|
||||
"name" VARCHAR(255) NOT NULL,
|
||||
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3),
|
||||
|
||||
CONSTRAINT "roles_pkey" PRIMARY KEY ("uid")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "rules" (
|
||||
"uid" TEXT NOT NULL,
|
||||
"name" VARCHAR(255) NOT NULL,
|
||||
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3),
|
||||
"role_has_rules_uid" TEXT,
|
||||
"office_role_has_rules_uid" TEXT,
|
||||
|
||||
CONSTRAINT "rules_pkey" PRIMARY KEY ("uid")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "role_has_rules" (
|
||||
"uid" TEXT NOT NULL,
|
||||
"role_uid" VARCHAR(255) NOT NULL,
|
||||
"rule_uid" VARCHAR(255) NOT NULL,
|
||||
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3),
|
||||
|
||||
CONSTRAINT "role_has_rules_pkey" PRIMARY KEY ("uid")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "office_role_has_rules" (
|
||||
"uid" TEXT NOT NULL,
|
||||
"role_uid" VARCHAR(255) NOT NULL,
|
||||
"rule_uid" VARCHAR(255) NOT NULL,
|
||||
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3),
|
||||
|
||||
CONSTRAINT "office_role_has_rules_pkey" PRIMARY KEY ("uid")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "addresses_uid_key" ON "addresses"("uid");
|
||||
|
||||
@ -366,12 +416,27 @@ CREATE UNIQUE INDEX "deed_type_has_document_types_uid_key" ON "deed_type_has_doc
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "deed_type_has_document_types_deed_type_uid_document_type_ui_key" ON "deed_type_has_document_types"("deed_type_uid", "document_type_uid");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "roles_uid_key" ON "roles"("uid");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "rules_uid_key" ON "rules"("uid");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "role_has_rules_uid_key" ON "role_has_rules"("uid");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "office_role_has_rules_uid_key" ON "office_role_has_rules"("uid");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "contacts" ADD CONSTRAINT "contacts_address_uid_fkey" FOREIGN KEY ("address_uid") REFERENCES "addresses"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_contact_uid_fkey" FOREIGN KEY ("contact_uid") REFERENCES "contacts"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_roles_uid_fkey" FOREIGN KEY ("roles_uid") REFERENCES "roles"("uid") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_office_uid_fkey" FOREIGN KEY ("office_uid") REFERENCES "offices"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
@ -444,6 +509,14 @@ ALTER TABLE "deed_type_has_document_types" ADD CONSTRAINT "deed_type_has_documen
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "deed_type_has_document_types" ADD CONSTRAINT "deed_type_has_document_types_deed_type_uid_fkey" FOREIGN KEY ("deed_type_uid") REFERENCES "deed_types"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "contacts" ALTER COLUMN "cell_phone_number" SET NOT NULL,
|
||||
ALTER COLUMN "address_uid" DROP NOT NULL;
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "rules" ADD CONSTRAINT "rules_role_has_rules_uid_fkey" FOREIGN KEY ("role_has_rules_uid") REFERENCES "role_has_rules"("uid") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "rules" ADD CONSTRAINT "rules_office_role_has_rules_uid_fkey" FOREIGN KEY ("office_role_has_rules_uid") REFERENCES "office_role_has_rules"("uid") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "role_has_rules" ADD CONSTRAINT "role_has_rules_role_uid_fkey" FOREIGN KEY ("role_uid") REFERENCES "roles"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "office_role_has_rules" ADD CONSTRAINT "office_role_has_rules_role_uid_fkey" FOREIGN KEY ("role_uid") REFERENCES "roles"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
@ -0,0 +1,14 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to alter the column `roles_uid` on the `users` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(255)`.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "users" DROP CONSTRAINT "users_roles_uid_fkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ALTER COLUMN "roles_uid" SET DATA TYPE VARCHAR(255);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_roles_uid_fkey" FOREIGN KEY ("roles_uid") REFERENCES "roles"("uid") ON DELETE RESTRICT ON UPDATE CASCADE;
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `office_role_has_rules_uid` on the `rules` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `role_has_rules_uid` on the `rules` table. All the data in the column will be lost.
|
||||
- Added the required column `office_uid` to the `office_role_has_rules` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "rules" DROP CONSTRAINT "rules_office_role_has_rules_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "rules" DROP CONSTRAINT "rules_role_has_rules_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "users" DROP CONSTRAINT "users_roles_uid_fkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "office_role_has_rules" ADD COLUMN "office_uid" VARCHAR(255) NOT NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "rules" DROP COLUMN "office_role_has_rules_uid",
|
||||
DROP COLUMN "role_has_rules_uid",
|
||||
ADD COLUMN "officesRolesHasRulesUid" TEXT,
|
||||
ADD COLUMN "rolesHasRulesUid" TEXT;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_roles_uid_fkey" FOREIGN KEY ("roles_uid") REFERENCES "roles"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "rules" ADD CONSTRAINT "rules_rolesHasRulesUid_fkey" FOREIGN KEY ("rolesHasRulesUid") REFERENCES "role_has_rules"("uid") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "rules" ADD CONSTRAINT "rules_officesRolesHasRulesUid_fkey" FOREIGN KEY ("officesRolesHasRulesUid") REFERENCES "office_role_has_rules"("uid") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "office_role_has_rules" ADD CONSTRAINT "office_role_has_rules_office_uid_fkey" FOREIGN KEY ("office_uid") REFERENCES "offices"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `officesRolesHasRulesUid` on the `rules` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `rolesHasRulesUid` on the `rules` table. All the data in the column will be lost.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "rules" DROP CONSTRAINT "rules_officesRolesHasRulesUid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "rules" DROP CONSTRAINT "rules_rolesHasRulesUid_fkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "rules" DROP COLUMN "officesRolesHasRulesUid",
|
||||
DROP COLUMN "rolesHasRulesUid",
|
||||
ADD COLUMN "office_role_has_rules_uid" TEXT,
|
||||
ADD COLUMN "role_has_rules_uid" TEXT;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "rules" ADD CONSTRAINT "rules_role_has_rules_uid_fkey" FOREIGN KEY ("role_has_rules_uid") REFERENCES "role_has_rules"("uid") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "rules" ADD CONSTRAINT "rules_office_role_has_rules_uid_fkey" FOREIGN KEY ("office_role_has_rules_uid") REFERENCES "office_role_has_rules"("uid") ON DELETE SET NULL ON UPDATE CASCADE;
|
@ -0,0 +1,12 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `rule_uid` on the `office_role_has_rules` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `rule_uid` on the `role_has_rules` table. All the data in the column will be lost.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "office_role_has_rules" DROP COLUMN "rule_uid";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "role_has_rules" DROP COLUMN "rule_uid";
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `office_role_has_rules_uid` on the `rules` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `role_has_rules_uid` on the `rules` table. All the data in the column will be lost.
|
||||
- Added the required column `rule_uid` to the `office_role_has_rules` table without a default value. This is not possible if the table is not empty.
|
||||
- Added the required column `rule_uid` to the `role_has_rules` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "rules" DROP CONSTRAINT "rules_office_role_has_rules_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "rules" DROP CONSTRAINT "rules_role_has_rules_uid_fkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "office_role_has_rules" ADD COLUMN "rule_uid" VARCHAR(255) NOT NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "role_has_rules" ADD COLUMN "rule_uid" VARCHAR(255) NOT NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "rules" DROP COLUMN "office_role_has_rules_uid",
|
||||
DROP COLUMN "role_has_rules_uid";
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "role_has_rules" ADD CONSTRAINT "role_has_rules_rule_uid_fkey" FOREIGN KEY ("rule_uid") REFERENCES "rules"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "office_role_has_rules" ADD CONSTRAINT "office_role_has_rules_rule_uid_fkey" FOREIGN KEY ("rule_uid") REFERENCES "rules"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
@ -0,0 +1,86 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the `office_role_has_rules` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `role_has_rules` table. If the table is not empty, all the data it contains will be lost.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "office_role_has_rules" DROP CONSTRAINT "office_role_has_rules_office_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "office_role_has_rules" DROP CONSTRAINT "office_role_has_rules_role_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "office_role_has_rules" DROP CONSTRAINT "office_role_has_rules_rule_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "role_has_rules" DROP CONSTRAINT "role_has_rules_role_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "role_has_rules" DROP CONSTRAINT "role_has_rules_rule_uid_fkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ADD COLUMN "office_role_uid" VARCHAR(255);
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "office_role_has_rules";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "role_has_rules";
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "office_roles" (
|
||||
"uid" TEXT NOT NULL,
|
||||
"name" VARCHAR(255) NOT NULL,
|
||||
"office_uid" VARCHAR(255) NOT NULL,
|
||||
"created_at" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3),
|
||||
|
||||
CONSTRAINT "office_roles_pkey" PRIMARY KEY ("uid")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "_RolesHasRules" (
|
||||
"A" TEXT NOT NULL,
|
||||
"B" TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "_OfficeRolesHasRules" (
|
||||
"A" TEXT NOT NULL,
|
||||
"B" TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "office_roles_uid_key" ON "office_roles"("uid");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "_RolesHasRules_AB_unique" ON "_RolesHasRules"("A", "B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "_RolesHasRules_B_index" ON "_RolesHasRules"("B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "_OfficeRolesHasRules_AB_unique" ON "_OfficeRolesHasRules"("A", "B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "_OfficeRolesHasRules_B_index" ON "_OfficeRolesHasRules"("B");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_office_role_uid_fkey" FOREIGN KEY ("office_role_uid") REFERENCES "office_roles"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "office_roles" ADD CONSTRAINT "office_roles_office_uid_fkey" FOREIGN KEY ("office_uid") REFERENCES "offices"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_RolesHasRules" ADD CONSTRAINT "_RolesHasRules_A_fkey" FOREIGN KEY ("A") REFERENCES "roles"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_RolesHasRules" ADD CONSTRAINT "_RolesHasRules_B_fkey" FOREIGN KEY ("B") REFERENCES "rules"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_OfficeRolesHasRules" ADD CONSTRAINT "_OfficeRolesHasRules_A_fkey" FOREIGN KEY ("A") REFERENCES "office_roles"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_OfficeRolesHasRules" ADD CONSTRAINT "_OfficeRolesHasRules_B_fkey" FOREIGN KEY ("B") REFERENCES "rules"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
144
src/common/databases/migrations/20230628100711_v7/migration.sql
Normal file
144
src/common/databases/migrations/20230628100711_v7/migration.sql
Normal file
@ -0,0 +1,144 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the `deed_has_document_types` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `deed_type_has_document_types` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `office_folder_has_customers` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `office_folder_has_stakeholder` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `user_has_notifications` table. If the table is not empty, all the data it contains will be lost.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "deed_has_document_types" DROP CONSTRAINT "deed_has_document_types_deed_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "deed_has_document_types" DROP CONSTRAINT "deed_has_document_types_document_type_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "deed_type_has_document_types" DROP CONSTRAINT "deed_type_has_document_types_deed_type_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "deed_type_has_document_types" DROP CONSTRAINT "deed_type_has_document_types_document_type_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "office_folder_has_customers" DROP CONSTRAINT "office_folder_has_customers_customer_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "office_folder_has_customers" DROP CONSTRAINT "office_folder_has_customers_office_folder_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "office_folder_has_stakeholder" DROP CONSTRAINT "office_folder_has_stakeholder_office_folder_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "office_folder_has_stakeholder" DROP CONSTRAINT "office_folder_has_stakeholder_user_stakeholder_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "user_has_notifications" DROP CONSTRAINT "user_has_notifications_notification_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "user_has_notifications" DROP CONSTRAINT "user_has_notifications_user_uid_fkey";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "deed_has_document_types";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "deed_type_has_document_types";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "office_folder_has_customers";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "office_folder_has_stakeholder";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "user_has_notifications";
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "_OfficeFolderHasCustomers" (
|
||||
"A" TEXT NOT NULL,
|
||||
"B" TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "_UserHasNotifications" (
|
||||
"A" TEXT NOT NULL,
|
||||
"B" TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "_OfficeFolderHasStakeholders" (
|
||||
"A" TEXT NOT NULL,
|
||||
"B" TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "_DeedHasDocumentTypes" (
|
||||
"A" TEXT NOT NULL,
|
||||
"B" TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "_DeedTypeHasDocumentTypes" (
|
||||
"A" TEXT NOT NULL,
|
||||
"B" TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "_OfficeFolderHasCustomers_AB_unique" ON "_OfficeFolderHasCustomers"("A", "B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "_OfficeFolderHasCustomers_B_index" ON "_OfficeFolderHasCustomers"("B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "_UserHasNotifications_AB_unique" ON "_UserHasNotifications"("A", "B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "_UserHasNotifications_B_index" ON "_UserHasNotifications"("B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "_OfficeFolderHasStakeholders_AB_unique" ON "_OfficeFolderHasStakeholders"("A", "B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "_OfficeFolderHasStakeholders_B_index" ON "_OfficeFolderHasStakeholders"("B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "_DeedHasDocumentTypes_AB_unique" ON "_DeedHasDocumentTypes"("A", "B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "_DeedHasDocumentTypes_B_index" ON "_DeedHasDocumentTypes"("B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "_DeedTypeHasDocumentTypes_AB_unique" ON "_DeedTypeHasDocumentTypes"("A", "B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "_DeedTypeHasDocumentTypes_B_index" ON "_DeedTypeHasDocumentTypes"("B");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_OfficeFolderHasCustomers" ADD CONSTRAINT "_OfficeFolderHasCustomers_A_fkey" FOREIGN KEY ("A") REFERENCES "customers"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_OfficeFolderHasCustomers" ADD CONSTRAINT "_OfficeFolderHasCustomers_B_fkey" FOREIGN KEY ("B") REFERENCES "office_folders"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_UserHasNotifications" ADD CONSTRAINT "_UserHasNotifications_A_fkey" FOREIGN KEY ("A") REFERENCES "notifications"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_UserHasNotifications" ADD CONSTRAINT "_UserHasNotifications_B_fkey" FOREIGN KEY ("B") REFERENCES "users"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_OfficeFolderHasStakeholders" ADD CONSTRAINT "_OfficeFolderHasStakeholders_A_fkey" FOREIGN KEY ("A") REFERENCES "office_folders"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_OfficeFolderHasStakeholders" ADD CONSTRAINT "_OfficeFolderHasStakeholders_B_fkey" FOREIGN KEY ("B") REFERENCES "users"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_DeedHasDocumentTypes" ADD CONSTRAINT "_DeedHasDocumentTypes_A_fkey" FOREIGN KEY ("A") REFERENCES "deed"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_DeedHasDocumentTypes" ADD CONSTRAINT "_DeedHasDocumentTypes_B_fkey" FOREIGN KEY ("B") REFERENCES "document_types"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_DeedTypeHasDocumentTypes" ADD CONSTRAINT "_DeedTypeHasDocumentTypes_A_fkey" FOREIGN KEY ("A") REFERENCES "deed_types"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_DeedTypeHasDocumentTypes" ADD CONSTRAINT "_DeedTypeHasDocumentTypes_B_fkey" FOREIGN KEY ("B") REFERENCES "document_types"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
@ -0,0 +1,23 @@
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "users" DROP CONSTRAINT "users_contact_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "users" DROP CONSTRAINT "users_office_role_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "users" DROP CONSTRAINT "users_office_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "users" DROP CONSTRAINT "users_roles_uid_fkey";
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_contact_uid_fkey" FOREIGN KEY ("contact_uid") REFERENCES "contacts"("uid") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_roles_uid_fkey" FOREIGN KEY ("roles_uid") REFERENCES "roles"("uid") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_office_role_uid_fkey" FOREIGN KEY ("office_role_uid") REFERENCES "office_roles"("uid") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_office_uid_fkey" FOREIGN KEY ("office_uid") REFERENCES "offices"("uid") ON DELETE RESTRICT ON UPDATE CASCADE;
|
@ -0,0 +1,15 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- A unique constraint covering the columns `[idNot,uid]` on the table `users` will be added. If there are existing duplicate values, this will fail.
|
||||
- A unique constraint covering the columns `[contact_uid,uid]` on the table `users` will be added. If there are existing duplicate values, this will fail.
|
||||
|
||||
*/
|
||||
-- DropIndex
|
||||
DROP INDEX "users_idNot_key";
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "users_idNot_uid_key" ON "users"("idNot", "uid");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "users_contact_uid_uid_key" ON "users"("contact_uid", "uid");
|
@ -0,0 +1,14 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- A unique constraint covering the columns `[idNot]` on the table `users` will be added. If there are existing duplicate values, this will fail.
|
||||
|
||||
*/
|
||||
-- DropIndex
|
||||
DROP INDEX "users_contact_uid_uid_key";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "users_idNot_uid_key";
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "users_idNot_key" ON "users"("idNot");
|
@ -0,0 +1,43 @@
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "users" DROP CONSTRAINT "users_contact_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "users" DROP CONSTRAINT "users_office_role_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "users" DROP CONSTRAINT "users_office_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "users" DROP CONSTRAINT "users_roles_uid_fkey";
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "email" (
|
||||
"uid" TEXT NOT NULL,
|
||||
"templateName" VARCHAR(255) NOT NULL,
|
||||
"from" VARCHAR(255),
|
||||
"to" VARCHAR(255) NOT NULL,
|
||||
"subject" VARCHAR(255) NOT NULL,
|
||||
"templateVariables" JSON NOT NULL DEFAULT '{}',
|
||||
"cc" VARCHAR(255)[],
|
||||
"cci" VARCHAR(255)[],
|
||||
"sentAt" TIMESTAMP(3),
|
||||
"nbTrySend" INTEGER DEFAULT 0,
|
||||
"lastTrySendDate" TIMESTAMP(3),
|
||||
|
||||
CONSTRAINT "email_pkey" PRIMARY KEY ("uid")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "email_uid_key" ON "email"("uid");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_contact_uid_fkey" FOREIGN KEY ("contact_uid") REFERENCES "contacts"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_roles_uid_fkey" FOREIGN KEY ("roles_uid") REFERENCES "roles"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_office_role_uid_fkey" FOREIGN KEY ("office_role_uid") REFERENCES "office_roles"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_office_uid_fkey" FOREIGN KEY ("office_uid") REFERENCES "offices"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
@ -0,0 +1,38 @@
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "users" DROP CONSTRAINT "users_contact_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "users" DROP CONSTRAINT "users_office_role_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "users" DROP CONSTRAINT "users_office_uid_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "users" DROP CONSTRAINT "users_roles_uid_fkey";
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "votes" (
|
||||
"uid" TEXT NOT NULL,
|
||||
"user_uid" VARCHAR(255) NOT NULL,
|
||||
"voters" TEXT[],
|
||||
|
||||
CONSTRAINT "votes_pkey" PRIMARY KEY ("uid")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "votes_uid_key" ON "votes"("uid");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_contact_uid_fkey" FOREIGN KEY ("contact_uid") REFERENCES "contacts"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_roles_uid_fkey" FOREIGN KEY ("roles_uid") REFERENCES "roles"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_office_role_uid_fkey" FOREIGN KEY ("office_role_uid") REFERENCES "office_roles"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_office_uid_fkey" FOREIGN KEY ("office_uid") REFERENCES "offices"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "votes" ADD CONSTRAINT "votes_user_uid_fkey" FOREIGN KEY ("user_uid") REFERENCES "users"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `user_uid` on the `votes` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `voters` on the `votes` table. All the data in the column will be lost.
|
||||
- Added the required column `appointment_uid` to the `votes` table without a default value. This is not possible if the table is not empty.
|
||||
- Added the required column `voter_uid` to the `votes` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- CreateEnum
|
||||
CREATE TYPE "EVote" AS ENUM ('NOMINATE', 'DISMISS');
|
||||
|
||||
-- CreateEnum
|
||||
CREATE TYPE "EAppointmentStatus" AS ENUM ('OPEN', 'CLOSED');
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "votes" DROP CONSTRAINT "votes_user_uid_fkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "votes" DROP COLUMN "user_uid",
|
||||
DROP COLUMN "voters",
|
||||
ADD COLUMN "appointment_uid" VARCHAR(255) NOT NULL,
|
||||
ADD COLUMN "choice" "EVote" NOT NULL DEFAULT 'NOMINATE',
|
||||
ADD COLUMN "voter_uid" VARCHAR(255) NOT NULL;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "appointments" (
|
||||
"uid" TEXT NOT NULL,
|
||||
"user_uid" VARCHAR(255) NOT NULL,
|
||||
"status" "EAppointmentStatus" NOT NULL DEFAULT 'OPEN',
|
||||
|
||||
CONSTRAINT "appointments_pkey" PRIMARY KEY ("uid")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "appointments_uid_key" ON "appointments"("uid");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "appointments" ADD CONSTRAINT "appointments_user_uid_fkey" FOREIGN KEY ("user_uid") REFERENCES "users"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "votes" ADD CONSTRAINT "votes_appointment_uid_fkey" FOREIGN KEY ("appointment_uid") REFERENCES "appointments"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "votes" ADD CONSTRAINT "votes_voter_uid_fkey" FOREIGN KEY ("voter_uid") REFERENCES "users"("uid") ON DELETE RESTRICT ON UPDATE CASCADE;
|
@ -0,0 +1,11 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `choice` on the `votes` table. All the data in the column will be lost.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "appointments" ADD COLUMN "choice" "EVote" NOT NULL DEFAULT 'NOMINATE';
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "votes" DROP COLUMN "choice";
|
@ -0,0 +1,8 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- A unique constraint covering the columns `[user_uid,choice,status]` on the table `appointments` will be added. If there are existing duplicate values, this will fail.
|
||||
|
||||
*/
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "appointments_user_uid_choice_status_key" ON "appointments"("user_uid", "choice", "status");
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user