Compare commits
18 Commits
89f9fbb4de
...
06e69d6974
Author | SHA1 | Date | |
---|---|---|---|
![]() |
06e69d6974 | ||
![]() |
e46739befe | ||
![]() |
86b81258b6 | ||
![]() |
5afa9d9a87 | ||
![]() |
c3c6185d9d | ||
![]() |
51c7c08c53 | ||
![]() |
4fdd163c90 | ||
![]() |
363c168479 | ||
![]() |
b2dfb98f2b | ||
![]() |
2435fb53b0 | ||
![]() |
497ff05ab1 | ||
![]() |
f3d9f3e6c8 | ||
![]() |
05191577eb | ||
![]() |
b048cfb1a0 | ||
![]() |
c33d4faacd | ||
![]() |
17c4347e98 | ||
![]() |
b2dbfbeaa2 | ||
![]() |
008d21de8c |
114
.github/workflows/demo.yml
vendored
114
.github/workflows/demo.yml
vendored
@ -1,114 +0,0 @@
|
|||||||
name: Demo - Build & Deploy to Scaleway
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [legacy_dev]
|
|
||||||
|
|
||||||
env:
|
|
||||||
PROJECT_ID_LECOFFRE: 72d08499-37c2-412b-877e-f8af0471654a
|
|
||||||
NAMESPACE_ID_LECOFFRE: c992c042-bdb6-4974-becf-aa5039b9ec58
|
|
||||||
CONTAINER_REGISTRY_ENDPOINT_LECOFFRE: rg.fr-par.scw.cloud/funcscwlecoffredemovts5gdxg
|
|
||||||
|
|
||||||
IMAGE_NAME: back
|
|
||||||
CONTAINER_NAME: back
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-and-push-images-lecoffre:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Setup SSH
|
|
||||||
run: |
|
|
||||||
mkdir -p ~/.ssh
|
|
||||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
|
|
||||||
chmod 600 ~/.ssh/id_rsa
|
|
||||||
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
|
|
||||||
env:
|
|
||||||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
|
||||||
- name: Copy SSH
|
|
||||||
run: cp ~/.ssh/id_rsa id_rsa
|
|
||||||
- name: Login to Scaleway Container Registry
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
with:
|
|
||||||
username: nologin
|
|
||||||
password: ${{ secrets.SCW_SECRET_KEY_LECOFFRE }}
|
|
||||||
registry: ${{ env.CONTAINER_REGISTRY_ENDPOINT_LECOFFRE }}
|
|
||||||
- name: Build the Back Image
|
|
||||||
run: docker build . -t ${{ env.CONTAINER_REGISTRY_ENDPOINT_LECOFFRE }}/${{ env.IMAGE_NAME }}
|
|
||||||
- name: Push the Back Image to Scaleway Container Registry
|
|
||||||
run: docker push ${{ env.CONTAINER_REGISTRY_ENDPOINT_LECOFFRE }}/${{ env.IMAGE_NAME }}
|
|
||||||
- name: Build the Cron Image
|
|
||||||
run: docker build -f Dockerfile-Cron . -t ${{ env.CONTAINER_REGISTRY_ENDPOINT_LECOFFRE }}/cron
|
|
||||||
- name: Push the Cron Image to Scaleway Container Registry
|
|
||||||
run: docker push ${{ env.CONTAINER_REGISTRY_ENDPOINT_LECOFFRE }}/cron
|
|
||||||
deploy-back-lecoffre:
|
|
||||||
needs: build-and-push-images-lecoffre
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
environment: demo
|
|
||||||
steps:
|
|
||||||
- name: Install CLI
|
|
||||||
uses: scaleway/action-scw@v0
|
|
||||||
- name: Get container ID
|
|
||||||
run: |
|
|
||||||
echo "CONTAINER_ID=$(scw container container list namespace-id=${{ env.NAMESPACE_ID_LECOFFRE }} -o json | jq -r '.[] | select(.name == "${{ env.CONTAINER_NAME }}") | .id')" >> $GITHUB_ENV
|
|
||||||
env:
|
|
||||||
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY_LECOFFRE }}
|
|
||||||
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY_LECOFFRE }}
|
|
||||||
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID_LECOFFRE }}
|
|
||||||
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID_LECOFFRE }}
|
|
||||||
- name: Deploy the container based on the new image
|
|
||||||
run: |
|
|
||||||
env_string=""
|
|
||||||
while IFS= read -r line; do
|
|
||||||
if [[ "$line" == *"="* ]]; then
|
|
||||||
key=$(echo "$line" | cut -d '=' -f 1)
|
|
||||||
value=$(echo "$line" | cut -d '=' -f 2-)
|
|
||||||
if [[ -n "$key" ]]; then
|
|
||||||
env_string+="environment-variables.$key=$value "
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done <<< "$ENV_VARS"
|
|
||||||
env_string=$(echo $env_string | sed 's/ $//')
|
|
||||||
scw container container update ${{ env.CONTAINER_ID }} $env_string
|
|
||||||
env:
|
|
||||||
ENV_VARS: ${{ secrets.ENV }}
|
|
||||||
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY_LECOFFRE }}
|
|
||||||
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY_LECOFFRE }}
|
|
||||||
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID_LECOFFRE }}
|
|
||||||
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID_LECOFFRE }}
|
|
||||||
deploy-cron-lecoffre:
|
|
||||||
needs: build-and-push-images-lecoffre
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
environment: demo
|
|
||||||
steps:
|
|
||||||
- name: Install CLI
|
|
||||||
uses: scaleway/action-scw@v0
|
|
||||||
- name: Get container ID
|
|
||||||
run: |
|
|
||||||
echo "CONTAINER_ID=$(scw container container list namespace-id=${{env.NAMESPACE_ID_LECOFFRE}} -o json | jq -r '.[] | select(.name == "cron") | .id')" >> $GITHUB_ENV
|
|
||||||
env:
|
|
||||||
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY_LECOFFRE }}
|
|
||||||
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY_LECOFFRE }}
|
|
||||||
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID_LECOFFRE }}
|
|
||||||
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID_LECOFFRE }}
|
|
||||||
- name: Deploy the container based on the new image
|
|
||||||
run: |
|
|
||||||
env_string=""
|
|
||||||
while IFS= read -r line; do
|
|
||||||
if [[ "$line" == *"="* ]]; then
|
|
||||||
key=$(echo "$line" | cut -d '=' -f 1)
|
|
||||||
value=$(echo "$line" | cut -d '=' -f 2-)
|
|
||||||
if [[ -n "$key" ]]; then
|
|
||||||
env_string+="environment-variables.$key=$value "
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done <<< "$ENV_VARS"
|
|
||||||
env_string=$(echo $env_string | sed 's/ $//')
|
|
||||||
scw container container update ${{ env.CONTAINER_ID }} $env_string
|
|
||||||
env:
|
|
||||||
ENV_VARS: ${{ secrets.ENV }}
|
|
||||||
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY_LECOFFRE }}
|
|
||||||
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY_LECOFFRE }}
|
|
||||||
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID_LECOFFRE }}
|
|
||||||
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID_LECOFFRE }}
|
|
||||||
|
|
35
.github/workflows/test.yml
vendored
35
.github/workflows/test.yml
vendored
@ -1,15 +1,14 @@
|
|||||||
name: Prod - Build & Deploy to Scaleway
|
name: Test - Build & Deploy to Scaleway
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [test]
|
branches: [legacy_dev]
|
||||||
|
|
||||||
env:
|
env:
|
||||||
|
|
||||||
PROJECT_ID_LECOFFRE: 72d08499-37c2-412b-877e-f8af0471654a
|
PROJECT_ID_LECOFFRE: 72d08499-37c2-412b-877e-f8af0471654a
|
||||||
NAMESPACE_ID_LECOFFRE: 3829c5cd-9fb0-4871-97a1-eb33e4bc1114
|
NAMESPACE_ID_LECOFFRE: 3829c5cd-9fb0-4871-97a1-eb33e4bc1114
|
||||||
CONTAINER_REGISTRY_ENDPOINT_LECOFFRE: rg.fr-par.scw.cloud/funcscwlecoffretestouylprmj
|
CONTAINER_REGISTRY_ENDPOINT_LECOFFRE: rg.fr-par.scw.cloud/funcscwlecoffretestouylprmj
|
||||||
|
|
||||||
IMAGE_NAME: back
|
IMAGE_NAME: back
|
||||||
CONTAINER_NAME: back
|
CONTAINER_NAME: back
|
||||||
|
|
||||||
@ -18,16 +17,16 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
#- name: Setup SSH
|
- name: Setup SSH
|
||||||
# run: |
|
run: |
|
||||||
# mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
# echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
|
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
|
||||||
# chmod 600 ~/.ssh/id_rsa
|
chmod 600 ~/.ssh/id_rsa
|
||||||
# ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
|
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
|
||||||
# env:
|
env:
|
||||||
# SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
#- name: Copy SSH
|
- name: Copy SSH
|
||||||
# run: cp ~/.ssh/id_rsa id_rsa
|
run: cp ~/.ssh/id_rsa id_rsa
|
||||||
- name: Login to Scaleway Container Registry
|
- name: Login to Scaleway Container Registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
@ -46,7 +45,7 @@ jobs:
|
|||||||
deploy-back-lecoffre:
|
deploy-back-lecoffre:
|
||||||
needs: build-and-push-images-lecoffre
|
needs: build-and-push-images-lecoffre
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
environment: prod
|
environment: test
|
||||||
steps:
|
steps:
|
||||||
- name: Install CLI
|
- name: Install CLI
|
||||||
uses: scaleway/action-scw@v0
|
uses: scaleway/action-scw@v0
|
||||||
@ -82,7 +81,7 @@ jobs:
|
|||||||
deploy-cron-lecoffre:
|
deploy-cron-lecoffre:
|
||||||
needs: build-and-push-images-lecoffre
|
needs: build-and-push-images-lecoffre
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
environment: prod
|
environment: test
|
||||||
steps:
|
steps:
|
||||||
- name: Install CLI
|
- name: Install CLI
|
||||||
uses: scaleway/action-scw@v0
|
uses: scaleway/action-scw@v0
|
||||||
@ -110,9 +109,7 @@ jobs:
|
|||||||
scw container container update ${{ env.CONTAINER_ID }} $env_string
|
scw container container update ${{ env.CONTAINER_ID }} $env_string
|
||||||
env:
|
env:
|
||||||
ENV_VARS: ${{ secrets.ENV }}
|
ENV_VARS: ${{ secrets.ENV }}
|
||||||
|
|
||||||
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY_LECOFFRE }}
|
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY_LECOFFRE }}
|
||||||
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY_LECOFFRE }}
|
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY_LECOFFRE }}
|
||||||
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID_LECOFFRE }}
|
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID_LECOFFRE }}
|
||||||
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID_LECOFFRE }}
|
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID_LECOFFRE }}
|
||||||
|
|
@ -3,7 +3,7 @@ import { Controller, Get, Post } from "@ControllerPattern/index";
|
|||||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import { Document, OfficeFolder, File } from "le-coffre-resources/dist/Notary";
|
import { Document, OfficeFolder, File } from "le-coffre-resources/dist/Notary";
|
||||||
import { getFolderHashes, getFolderFilesUid } from "@Common/optics/notary";
|
import { getFolderFilesUid } from "@Common/optics/notary";
|
||||||
import OfficeFoldersService from "@Services/notary/OfficeFoldersService/OfficeFoldersService";
|
import OfficeFoldersService from "@Services/notary/OfficeFoldersService/OfficeFoldersService";
|
||||||
import OfficeFolderAnchorsRepository from "@Repositories/OfficeFolderAnchorsRepository";
|
import OfficeFolderAnchorsRepository from "@Repositories/OfficeFolderAnchorsRepository";
|
||||||
import FilesService from "@Services/common/FilesService/FilesService";
|
import FilesService from "@Services/common/FilesService/FilesService";
|
||||||
@ -49,6 +49,27 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getValidatedDocumentHashes(officeFolder: OfficeFolder): string[] {
|
||||||
|
const documents = officeFolder.documents ?? [];
|
||||||
|
|
||||||
|
if (documents.length === 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const folderHashes: string[] = [];
|
||||||
|
documents.forEach((document: any) => {
|
||||||
|
const documentHydrated = Document.hydrate<Document>(document, { strategy: "excludeAll" });
|
||||||
|
if (documentHydrated.document_status === "VALIDATED") {
|
||||||
|
documentHydrated.files?.forEach((file: any) => {
|
||||||
|
const fileHydrated = File.hydrate<File>(file, { strategy: "excludeAll" });
|
||||||
|
folderHashes.push(fileHydrated.hash);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return folderHashes.sort();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Download a folder anchoring proof document along with all accessible files
|
* @description Download a folder anchoring proof document along with all accessible files
|
||||||
*/
|
*/
|
||||||
@ -79,15 +100,14 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderFound, { strategy: "excludeAll" });
|
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderFound, { strategy: "excludeAll" });
|
||||||
const folderHashes = getFolderHashes(officeFolder);
|
const sortedHashes = this.getValidatedDocumentHashes(officeFolder);
|
||||||
const folderFilesUid = getFolderFilesUid(officeFolder);
|
const folderFilesUid = getFolderFilesUid(officeFolder);
|
||||||
|
|
||||||
if (folderHashes.length === 0) {
|
if (sortedHashes.length === 0) {
|
||||||
this.httpNotFoundRequest(response, "No file hash to anchor");
|
this.httpNotFoundRequest(response, "No file hash to anchor");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sortedHashes = [...folderHashes].sort();
|
|
||||||
const anchoringProof = await this.secureService.download(sortedHashes, officeFolder.office!.name);
|
const anchoringProof = await this.secureService.download(sortedHashes, officeFolder.office!.name);
|
||||||
|
|
||||||
|
|
||||||
@ -180,18 +200,13 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const folderHashes: string[] = [];
|
const sortedHashes = this.getValidatedDocumentHashes(officeFolder);
|
||||||
documents.forEach((document: any) => {
|
|
||||||
const documentHydrated = Document.hydrate<Document>(document, { strategy: "excludeAll" });
|
if (sortedHashes.length === 0) {
|
||||||
if (documentHydrated.document_status === "VALIDATED") {
|
this.httpBadRequest(response, "No file hash to anchor");
|
||||||
documentHydrated.files?.forEach((file: any) => {
|
return;
|
||||||
const fileHydrated = File.hydrate<File>(file, { strategy: "excludeAll" });
|
}
|
||||||
folderHashes.push(fileHydrated.hash);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const sortedHashes = [...folderHashes].sort();
|
|
||||||
const data = await this.secureService.anchor(sortedHashes);
|
const data = await this.secureService.anchor(sortedHashes);
|
||||||
|
|
||||||
const officeFolderAnchor = hydrateOfficeFolderAnchor(data);
|
const officeFolderAnchor = hydrateOfficeFolderAnchor(data);
|
||||||
@ -248,23 +263,13 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const folderHashes: string[] = [];
|
const sortedHashes = this.getValidatedDocumentHashes(officeFolder);
|
||||||
documents.forEach((document: any) => {
|
|
||||||
const documentHydrated = Document.hydrate<Document>(document, { strategy: "excludeAll" });
|
|
||||||
if (documentHydrated.document_status === "VALIDATED") {
|
|
||||||
documentHydrated.files?.forEach((file: any) => {
|
|
||||||
const fileHydrated = File.hydrate<File>(file, { strategy: "excludeAll" });
|
|
||||||
folderHashes.push(fileHydrated.hash);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (folderHashes.length === 0) {
|
if (sortedHashes.length === 0) {
|
||||||
this.httpNotFoundRequest(response, "No file hash to anchor");
|
this.httpNotFoundRequest(response, "No file hash to anchor");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sortedHashes = [...folderHashes].sort();
|
|
||||||
const officeFolderAnchorFound = OfficeFolderAnchor.hydrate<OfficeFolderAnchor>(officeFolderFound.folder_anchor, {
|
const officeFolderAnchorFound = OfficeFolderAnchor.hydrate<OfficeFolderAnchor>(officeFolderFound.folder_anchor, {
|
||||||
strategy: "excludeAll",
|
strategy: "excludeAll",
|
||||||
});
|
});
|
||||||
|
@ -95,7 +95,7 @@ export default class NotificationBuilder {
|
|||||||
redirection_url: "",
|
redirection_url: "",
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
user: [user] || [],
|
user: user ? [user] : [],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ export default class NotificationBuilder {
|
|||||||
redirection_url: "",
|
redirection_url: "",
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
user: [user] || [],
|
user: user ? [user] : [],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,9 +100,9 @@ export default class UsersRepository extends BaseRepository {
|
|||||||
update: {
|
update: {
|
||||||
first_name: user.contact?.first_name,
|
first_name: user.contact?.first_name,
|
||||||
last_name: user.contact?.last_name,
|
last_name: user.contact?.last_name,
|
||||||
email: user.contact?.email,
|
email: user.contact?.email === null ? undefined : user.contact?.email,
|
||||||
phone_number: user.contact?.phone_number,
|
phone_number: user.contact?.phone_number === null ? undefined : user.contact?.phone_number,
|
||||||
cell_phone_number: user.contact?.cell_phone_number,
|
cell_phone_number: user.contact?.cell_phone_number === null ? undefined : user.contact?.cell_phone_number,
|
||||||
civility: ECivility[user.contact?.civility as keyof typeof ECivility],
|
civility: ECivility[user.contact?.civility as keyof typeof ECivility],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -50,6 +50,7 @@ interface IRattachementData {
|
|||||||
numeroTelephone: string;
|
numeroTelephone: string;
|
||||||
statutDuRattachement: boolean;
|
statutDuRattachement: boolean;
|
||||||
mailRattachement: string;
|
mailRattachement: string;
|
||||||
|
deleted: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IOfficeData {
|
interface IOfficeData {
|
||||||
@ -225,45 +226,63 @@ export default class IdNotService extends BaseService {
|
|||||||
key: this.variables.IDNOT_API_KEY,
|
key: this.variables.IDNOT_API_KEY,
|
||||||
});
|
});
|
||||||
|
|
||||||
let userData: IRattachementData;
|
let userRawData: Response;
|
||||||
try {
|
try {
|
||||||
userData = (await (
|
userRawData = await fetch(
|
||||||
await fetch(
|
|
||||||
`${this.variables.IDNOT_API_BASE_URL}/api/pp/v2/rattachements/${user.idNot}_${user.office_membership!.idNot}?` +
|
`${this.variables.IDNOT_API_BASE_URL}/api/pp/v2/rattachements/${user.idNot}_${user.office_membership!.idNot}?` +
|
||||||
searchParams,
|
searchParams,
|
||||||
{
|
{
|
||||||
method: "GET",
|
method: "GET",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
).json()) as IRattachementData;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching user data", error);
|
console.error(`Error fetching user data for ${user.uid}: ${error}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userRawData.status === 404) {
|
||||||
|
console.error(`User ${user.uid} not found in idnot`);
|
||||||
|
return;
|
||||||
|
} else if (userRawData.status !== 200) {
|
||||||
|
console.error(`Error fetching user data for ${user.uid}: ${userRawData.status} - ${userRawData.statusText}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!userData.statutDuRattachement) {
|
let userData = (await userRawData.json()) as IRattachementData;
|
||||||
|
|
||||||
|
if (userData.deleted) {
|
||||||
let rattachements: any;
|
let rattachements: any;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
rattachements = (await (
|
const res = await fetch(`${this.variables.IDNOT_API_BASE_URL}/api/pp/v2/personnes/${user.idNot}/rattachements?` + searchParams, {
|
||||||
await fetch(`${this.variables.IDNOT_API_BASE_URL}/api/pp/v2/personnes/${user.idNot}/rattachements?` + searchParams, {
|
method: "GET",
|
||||||
method: "GET",
|
});
|
||||||
})
|
if (res.status === 404) {
|
||||||
).json()) as any;
|
console.error(`User ${user.uid} not found in idnot`);
|
||||||
|
return;
|
||||||
|
} else if (res.status !== 200) {
|
||||||
|
console.error(`Error fetching rattachements for ${user.uid}: ${rattachements.status} - ${rattachements.statusText}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rattachements = await res.json();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching rattachements", error);
|
console.error("Error fetching rattachements", error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rattachements.totalResultCount === 0) {
|
if (rattachements && rattachements.totalResultCount === 0 && rattachements.result.length === 0) {
|
||||||
|
console.warn("User has no valid rattachements", user.uid);
|
||||||
await this.userService.updateCheckedAt(user.uid!);
|
await this.userService.updateCheckedAt(user.uid!);
|
||||||
//await this.userService.delete(user.uid!);
|
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
console.log(`Found ${rattachements.totalResultCount} rattachements for ${user.uid}`);
|
||||||
}
|
}
|
||||||
const rattachementsResults = rattachements.result as IRattachementData[];
|
const rattachementsResults = rattachements.result as IRattachementData[];
|
||||||
if (!rattachementsResults) return;
|
if (!rattachementsResults) return;
|
||||||
rattachementsResults.forEach(async (rattachement) => {
|
|
||||||
if (rattachement.statutDuRattachement) {
|
for (const rattachement of rattachementsResults) {
|
||||||
|
if (rattachement.statutDuRattachement && !rattachement.deleted) {
|
||||||
let officeData: IOfficeData;
|
let officeData: IOfficeData;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -274,20 +293,22 @@ export default class IdNotService extends BaseService {
|
|||||||
).json()) as IOfficeData;
|
).json()) as IOfficeData;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching office data", error);
|
console.error("Error fetching office data", error);
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (officeData.typeEntite.name === "office") {
|
if (officeData.typeEntite.name === "office") {
|
||||||
userData = rattachement;
|
userData = rattachement;
|
||||||
|
userData.entite = officeData;
|
||||||
|
break; // Found the first valid office, no need to continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let updates = 0;
|
let update = false;
|
||||||
|
|
||||||
if (user.office_membership!.idNot !== userData.entite.ou) {
|
if (user.office_membership!.idNot !== userData.entite.ou) {
|
||||||
updates++;
|
update = true;
|
||||||
let officeData = (await this.officeService.get({ where: { idNot: userData.entite.ou } }))[0];
|
let officeData = (await this.officeService.get({ where: { idNot: userData.entite.ou } }))[0];
|
||||||
if (!officeData) {
|
if (!officeData) {
|
||||||
let officeLocationData: IOfficeLocation;
|
let officeLocationData: IOfficeLocation;
|
||||||
@ -321,17 +342,25 @@ export default class IdNotService extends BaseService {
|
|||||||
officeData = await this.officeService.create(office);
|
officeData = await this.officeService.create(office);
|
||||||
}
|
}
|
||||||
user.office_membership = officeData;
|
user.office_membership = officeData;
|
||||||
|
console.log("New office_membership found", JSON.stringify(user.office_membership));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.contact!.email !== userData.mailRattachement) {
|
if (userData.mailRattachement && (user.contact!.email === null || user.contact!.email === undefined || user.contact!.email !== userData.mailRattachement)) {
|
||||||
updates++;
|
update = true;
|
||||||
user.contact!.email = userData.mailRattachement;
|
user.contact!.email = userData.mailRattachement;
|
||||||
|
console.log("New email found", JSON.stringify(user.contact!.email));
|
||||||
}
|
}
|
||||||
if (user.contact!.cell_phone_number !== userData.numeroMobile) {
|
if (userData.numeroMobile && (user.contact!.cell_phone_number === null || user.contact!.cell_phone_number === undefined || user.contact!.cell_phone_number !== userData.numeroMobile)) {
|
||||||
updates++;
|
update = true;
|
||||||
user.contact!.cell_phone_number = userData.numeroMobile;
|
user.contact!.cell_phone_number = userData.numeroMobile;
|
||||||
|
console.log("New cell phone number found", JSON.stringify(user.contact!.cell_phone_number));
|
||||||
|
}
|
||||||
|
if (update) {
|
||||||
|
console.log("Found updates for user", user.uid!);
|
||||||
|
// Filter out null values before updating to prevent Prisma errors
|
||||||
|
const convertedUser = this.convertNullToUndefined(user);
|
||||||
|
await this.userService.update(user.uid!, convertedUser);
|
||||||
}
|
}
|
||||||
if (updates != 0) await this.userService.update(user.uid!, user);
|
|
||||||
await this.userService.updateCheckedAt(user.uid!);
|
await this.userService.updateCheckedAt(user.uid!);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,19 +388,20 @@ export default class IdNotService extends BaseService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const officeData = (await officeRawData.json()) as IOfficeData;
|
const officeData = (await officeRawData.json()) as IOfficeData;
|
||||||
console.log("office", office);
|
|
||||||
|
|
||||||
console.log("officeData", officeData);
|
|
||||||
|
|
||||||
let updates = 0;
|
let updates = 0;
|
||||||
//093051 = demo
|
//093051 = demo
|
||||||
if (office.name !== officeData.denominationSociale && office.name !== officeData.codeCrpcen && office.crpcen !== "029178" && office.crpcen !== "035010" && office.crpcen !== "093051") {
|
if (office.name !== officeData.denominationSociale && office.name !== officeData.codeCrpcen && office.crpcen !== "029178" && office.crpcen !== "035010" && office.crpcen !== "093051") {
|
||||||
|
console.log(`Updating office name: ${office.uid} - ${office.name} - ${office.crpcen}`);
|
||||||
updates++;
|
updates++;
|
||||||
office.name = officeData.denominationSociale ?? officeData.codeCrpcen;
|
office.name = officeData.denominationSociale ?? officeData.codeCrpcen;
|
||||||
|
console.log(`New name: ${office.name}`);
|
||||||
}
|
}
|
||||||
if (office.office_status !== this.getOfficeStatus(officeData.statutEntite.name)) {
|
if (office.office_status !== this.getOfficeStatus(officeData.statutEntite.name)) {
|
||||||
|
console.log(`Updating office status: ${office.uid} - ${office.name} - ${office.crpcen}`);
|
||||||
updates++;
|
updates++;
|
||||||
office.office_status = this.getOfficeStatus(officeData.statutEntite.name);
|
office.office_status = this.getOfficeStatus(officeData.statutEntite.name);
|
||||||
|
console.log(`New status: ${office.office_status}`);
|
||||||
}
|
}
|
||||||
if (updates != 0) await this.officeService.update(office.uid!, office);
|
if (updates != 0) await this.officeService.update(office.uid!, office);
|
||||||
await this.officeService.updateCheckedAt(office.uid!);
|
await this.officeService.updateCheckedAt(office.uid!);
|
||||||
@ -541,16 +571,36 @@ export default class IdNotService extends BaseService {
|
|||||||
public async updateUsers() {
|
public async updateUsers() {
|
||||||
const usersReq = await this.userService.getUsersToBeChecked();
|
const usersReq = await this.userService.getUsersToBeChecked();
|
||||||
const users = User.hydrateArray<User>(usersReq);
|
const users = User.hydrateArray<User>(usersReq);
|
||||||
users.forEach(async (user) => {
|
for (const user of users) {
|
||||||
await this.updateUser(user.uid!);
|
await this.updateUser(user.uid!);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateOffices() {
|
public async updateOffices() {
|
||||||
const officesReq = await this.officeService.getOfficesToBeChecked();
|
const officesReq = await this.officeService.getOfficesToBeChecked();
|
||||||
const offices = Office.hydrateArray<Office>(officesReq);
|
const offices = Office.hydrateArray<Office>(officesReq);
|
||||||
offices.forEach(async (office) => {
|
console.log(`Updating ${offices.length} offices`);
|
||||||
|
for (const office of offices) {
|
||||||
await this.updateOffice(office.uid!);
|
await this.updateOffice(office.uid!);
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility function to convert null values to undefined
|
||||||
|
* This prevents Prisma from throwing errors about null values
|
||||||
|
*/
|
||||||
|
private convertNullToUndefined<T extends Record<string, any>>(obj: T): T {
|
||||||
|
const converted = { ...obj };
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(converted)) {
|
||||||
|
if (value === null) {
|
||||||
|
console.log(`Converting null to undefined for key: ${key}`);
|
||||||
|
(converted as any)[key] = undefined;
|
||||||
|
} else if (typeof value === 'object' && !Array.isArray(value)) {
|
||||||
|
(converted as any)[key] = this.convertNullToUndefined(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return converted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user