From 1ab0a239c79b447f03b375bdcefe69906b9d0839 Mon Sep 17 00:00:00 2001 From: Caroline <4971715+carolineBda@users.noreply.github.com> Date: Tue, 10 May 2022 14:33:46 +0200 Subject: [PATCH 1/2] feat(cron): fetch data from DS in one cron, and using the latest updated dossier date (#159) --- .env.production | 1 + .env.staging | 1 + .env.test | 1 + .../preprod/templates/importData.yaml | 2 +- .../preprod/templates/importState.yaml | 28 --- .kube-workflow/prod/templates/importData.yaml | 2 +- .../prod/templates/importState.yaml | 28 --- README.md | 25 +++ src/__tests__/cron/import-state.spec.ts | 165 +++++++++++++----- src/cron/demarchesSimplifiees.ts | 50 +++--- src/cron/launch.ts | 3 +- src/db/seeds/psychologist.ts | 2 +- .../__tests__/ds-parse-psychologists.spec.ts | 2 +- src/services/__tests__/psychologists.spec.ts | 47 +++++ src/services/config.ts | 1 + .../demarchesSimplifiees/buildRequest.ts | 28 +-- src/services/demarchesSimplifiees/import.ts | 47 +---- src/services/getAddressCoordinates.ts | 5 +- src/services/psychologists.ts | 30 ++-- 19 files changed, 260 insertions(+), 208 deletions(-) delete mode 100644 .kube-workflow/preprod/templates/importState.yaml delete mode 100644 .kube-workflow/prod/templates/importState.yaml diff --git a/.env.production b/.env.production index 8db2ca47..c84c7850 100644 --- a/.env.production +++ b/.env.production @@ -19,3 +19,4 @@ MAIL_TLS=true MAIL_ENABLED=true SUPPORT_MAIL=monpsysante@fabrique.social.gouv.fr +API_ADRESSE_URL=https://api-adresse.data.gouv.fr/search diff --git a/.env.staging b/.env.staging index b36c4c7d..cd4b009c 100644 --- a/.env.staging +++ b/.env.staging @@ -17,3 +17,4 @@ MAIL_TLS=true MAIL_ENABLED=true SUPPORT_MAIL=monpsysante@fabrique.social.gouv.fr +API_ADRESSE_URL=https://api-adresse.data.gouv.fr/search diff --git a/.env.test b/.env.test index 949a4da2..c6ea284c 100644 --- a/.env.test +++ b/.env.test @@ -14,3 +14,4 @@ MAIL_ENABLED=false SUPPORT_MAIL=monpsysante@fabrique.social.gouv.fr NEXTAUTH_URL=http://localhost:3000 +API_ADRESSE_URL=https://httpbin.org/apiAdresse diff --git a/.kube-workflow/preprod/templates/importData.yaml b/.kube-workflow/preprod/templates/importData.yaml index cdb366d6..2d520de3 100644 --- a/.kube-workflow/preprod/templates/importData.yaml +++ b/.kube-workflow/preprod/templates/importData.yaml @@ -23,6 +23,6 @@ spec: - yarn - run - cron:launch - - importData + - importFromDS restartPolicy: Never concurrencyPolicy: Forbid diff --git a/.kube-workflow/preprod/templates/importState.yaml b/.kube-workflow/preprod/templates/importState.yaml deleted file mode 100644 index a4df6810..00000000 --- a/.kube-workflow/preprod/templates/importState.yaml +++ /dev/null @@ -1,28 +0,0 @@ -apiVersion: batch/v1beta1 -kind: CronJob -metadata: - namespace: mon-psy-sante-preprod - name: import-state - labels: - app: mon-psy -spec: - schedule: "0 */3 * * *" - jobTemplate: - spec: - template: - spec: - containers: - - name: mon-psy - image: ghcr.io/socialgouv/mon-psy-sante/app:{{ .Values.global.imageTag }} - envFrom: - - secretRef: - name: app-sealed-secret - - secretRef: - name: pg-user - command: - - yarn - - run - - cron:launch - - importState - restartPolicy: Never - concurrencyPolicy: Forbid diff --git a/.kube-workflow/prod/templates/importData.yaml b/.kube-workflow/prod/templates/importData.yaml index 9ad792a5..32457cc7 100644 --- a/.kube-workflow/prod/templates/importData.yaml +++ b/.kube-workflow/prod/templates/importData.yaml @@ -23,6 +23,6 @@ spec: - yarn - run - cron:launch - - importData + - importFromDS restartPolicy: Never concurrencyPolicy: Forbid diff --git a/.kube-workflow/prod/templates/importState.yaml b/.kube-workflow/prod/templates/importState.yaml deleted file mode 100644 index 8a8f68ad..00000000 --- a/.kube-workflow/prod/templates/importState.yaml +++ /dev/null @@ -1,28 +0,0 @@ -apiVersion: batch/v1beta1 -kind: CronJob -metadata: - namespace: mon-psy-sante - name: import-state - labels: - app: mon-psy -spec: - schedule: "0 */3 * * *" - jobTemplate: - spec: - template: - spec: - containers: - - name: mon-psy - image: ghcr.io/socialgouv/mon-psy-sante/app:{{ .Values.global.imageTag }} - envFrom: - - secretRef: - name: app-sealed-secret - - secretRef: - name: pg-user - command: - - yarn - - run - - cron:launch - - importState - restartPolicy: Never - concurrencyPolicy: Forbid diff --git a/README.md b/README.md index 8d52bb36..20066dca 100644 --- a/README.md +++ b/README.md @@ -56,3 +56,28 @@ To re-run the migration from 0 ## To update sealed secret https://socialgouv.github.io/sre-tools/ + + +## How to connect app to db on bastion + +- open ssh tunnel : + +``` +ssh -l localhost:54320:.postgres.database.azure.com:5432 @fabrique-bastion +``` + +- dans la connection Sequelize, deactivate ssl : + +``` + dialectOptions: { + ssl: { + rejectUnauthorized: false, + }, + }, +``` + +- set la var d'env DATABASE_URL pour pointer vers localhost et le protocole est `postgre`: + +``` +DATABASE_URL=postgres://:@localhost:54320/prod +``` diff --git a/src/__tests__/cron/import-state.spec.ts b/src/__tests__/cron/import-state.spec.ts index 820f3987..b2ce6a44 100644 --- a/src/__tests__/cron/import-state.spec.ts +++ b/src/__tests__/cron/import-state.spec.ts @@ -1,4 +1,10 @@ -import { importState } from "../../cron/demarchesSimplifiees"; +import axios from "axios"; + +import { + importArchived, + importData, + importFromDS, +} from "../../cron/demarchesSimplifiees"; import { models } from "../../db/models"; import { getOnePsychologist } from "../../db/seeds/psychologist"; import { request } from "../../services/demarchesSimplifiees/request"; @@ -6,6 +12,8 @@ import { Psychologist } from "../../types/psychologist"; jest.mock("../../services/demarchesSimplifiees/request"); +jest.mock("axios"); + function formatForDS(psy: Psychologist) { return Object.assign( { @@ -44,9 +52,9 @@ function formatForDS(psy: Psychologist) { } const states = ["accepte", "en_instruction", "refuse"]; -const archiveds = [true, false]; +const archived = [true, false]; -const psychologistsInDB = archiveds.flatMap((archived) => +const psychologistsInDB = archived.flatMap((archived) => states.flatMap((state) => getOnePsychologist({ archived, @@ -66,62 +74,127 @@ const psychologistsInDS = psychologistsInDB.map((psy) => { return formatForDS(psy); }); -const newPsy = formatForDS( - getOnePsychologist({ - state: "accepte", - address: "newPsy", - instructorId: "psyInDB", - }) -); -psychologistsInDS.push(newPsy); -const updatedPsy = formatForDS(psyHasChanged); -updatedPsy.state = "refuse"; -psychologistsInDS.push(updatedPsy); - -describe("Cron import State", () => { - beforeEach(async () => { - await models.Psychologist.destroy({ where: {} }); - - //@ts-ignore - await models.Psychologist.bulkCreate(psychologistsInDB); - +describe("Cron import from DS", () => { + function mockDSCall(psychologistsInDS) { // @ts-ignore request.mockImplementationOnce(() => Promise.resolve({ demarche: { dossiers: { nodes: psychologistsInDS, pageInfo: {} } }, }) ); + } - //@ts-ignore - request.mockImplementationOnce(() => - Promise.resolve({ dossier: updatedPsy }) - ); - //@ts-ignore - request.mockImplementationOnce(() => Promise.resolve({ dossier: newPsy })); - }); - - it("Should add missing psy", async () => { + beforeEach(() => { // @ts-ignore - const psyBefore: Psychologist = await models.Psychologist.findOne({ - where: { id: psyHasChanged.id }, - raw: true, + axios.get.mockImplementation(() => Promise.resolve({ data: {} })); + }); + describe("With no data in DB", () => { + beforeEach(async () => { + await models.Psychologist.destroy({ where: {} }); + mockDSCall(psychologistsInDS); + mockDSCall([]); }); - expect(psyBefore.state).toEqual("accepte"); - await importState(); + it("Should import all psy", async () => { + // @ts-ignore + let psychologists: Psychologist[] = await models.Psychologist.findAll({ + raw: true, + }); + expect(psychologists.length).toBe(0); - // @ts-ignore - const psychologists: Psychologist[] = await models.Psychologist.findAll({ - where: { instructorId: "psyInDB" }, - raw: true, + await importFromDS(); + + // @ts-ignore + psychologists = await models.Psychologist.findAll({ raw: true }); + + expect(psychologists.length).toEqual(7); + const psychologist = psychologists.find( + (psy) => psy.address === "psyHasChanged" + ); + expect(psychologist.state).toEqual("accepte"); + expect(psychologist.archived).toEqual(false); }); + }); + + describe("With data in DB", () => { + const updatedPsy = formatForDS(psyHasChanged); + updatedPsy.state = "sans_suite"; + updatedPsy.archived = true; - expect(psychologists.length).toEqual(8); - expect(psychologists.find((psy) => psy.address === "newPsy").state).toEqual( - "accepte" + const newPsy = formatForDS( + getOnePsychologist({ + state: "accepte", + address: "newPsy", + instructorId: "psyInDB", + }) ); - expect( - psychologists.find((psy) => psy.address === "psyHasChanged").state - ).toEqual("refuse"); + + beforeEach(async () => { + await models.Psychologist.destroy({ where: {} }); + + //@ts-ignore + await models.Psychologist.bulkCreate(psychologistsInDB); + + // @ts-ignore + request.mockImplementationOnce(() => + Promise.resolve({ + demarche: { dossiers: { nodes: [newPsy], pageInfo: {} } }, + }) + ); + + // @ts-ignore + request.mockImplementationOnce(() => + Promise.resolve({ + demarche: { dossiers: { nodes: [updatedPsy], pageInfo: {} } }, + }) + ); + }); + + it("Should add new psy", async () => { + // @ts-ignore + const psyBefore: Psychologist = await models.Psychologist.findOne({ + where: { address: newPsy.address }, + raw: true, + }); + expect(psyBefore).toEqual(null); + + await importData(); + // @ts-ignore + const psychologists: Psychologist[] = await models.Psychologist.findAll({ + where: { instructorId: "psyInDB" }, + raw: true, + }); + + expect(psychologists.length).toEqual(8); + const psychologist = psychologists.find( + (psy) => psy.address === newPsy.address + ); + expect(psychologist.state).toEqual("accepte"); + expect(psychologist.archived).toEqual(false); + }); + + it("Should update psy state", async () => { + // @ts-ignore + const psyBefore: Psychologist = await models.Psychologist.findOne({ + where: { id: updatedPsy.id }, + raw: true, + }); + expect(psyBefore.state).toEqual("accepte"); + + await importArchived(); + + // @ts-ignore + const psychologists: Psychologist[] = await models.Psychologist.findAll({ + where: { instructorId: "psyInDB" }, + raw: true, + }); + + expect(psychologists.length).toEqual(7); + const psychologist = psychologists.find( + (psy) => psy.id === updatedPsy.id + ); + expect(psychologist.state).toEqual("sans_suite"); + expect(psychologist.archived).toEqual(true); + }); }); }); diff --git a/src/cron/demarchesSimplifiees.ts b/src/cron/demarchesSimplifiees.ts index 201af336..a0b80c09 100644 --- a/src/cron/demarchesSimplifiees.ts +++ b/src/cron/demarchesSimplifiees.ts @@ -1,21 +1,19 @@ import * as Sentry from "@sentry/nextjs"; import pLimit from "p-limit"; -import { models } from "../db/models"; import { requestAdeli } from "../services/adeli/request"; import { addVerificationMessage } from "../services/demarchesSimplifiees/buildRequest"; import filterDossiersToVerif from "../services/demarchesSimplifiees/dossiers"; import { getDossiersInConstruction, - getPsychologistFromListIds, getPsychologistList, - getPsychologistState, } from "../services/demarchesSimplifiees/import"; import parsePsychologists from "../services/demarchesSimplifiees/parse-psychologists"; import { validatePsychologist } from "../services/demarchesSimplifiees/validate-psychologist"; import { countAll, - filterIdsNotInDb, + getDateLatestAccepte, + getDateLatestArchived, saveMany, updateState, } from "../services/psychologists"; @@ -33,23 +31,13 @@ export const importData = async (): Promise => { try { console.log("Starting importData..."); await logPsyNumber(); - const latestCursor = await models.DSCursor.findOne({ - raw: true, - where: { id: 1 }, - }); + const date = await getDateLatestAccepte(); //@ts-ignore - const dsAPIData = await getPsychologistList(latestCursor.cursor); + const dsAPIData = await getPsychologistList(date, "state: accepte"); if (dsAPIData.psychologists.length > 0) { await saveMany(dsAPIData.psychologists); console.log(`${dsAPIData.psychologists.length} saved`); - await models.DSCursor.update( - { - cursor: dsAPIData.lastCursor, - }, - { where: { id: 1 } } - ); - console.log(`New cursor ${dsAPIData.lastCursor} saved`); } console.log(`Import done`); @@ -60,30 +48,32 @@ export const importData = async (): Promise => { } }; -export const importState = async (): Promise => { +export const importArchived = async (): Promise => { try { - console.log("Starting importState."); + console.log("Starting importArchived."); await logPsyNumber(); - const dsAPIData = await getPsychologistState(); - - await updateState(dsAPIData); - const missingPsy: number[] = await filterIdsNotInDb( - dsAPIData.filter((psy) => psy.state === "accepte") - ); - if (missingPsy.length) { - const missingPsyData = await getPsychologistFromListIds(missingPsy); - await saveMany(missingPsyData); - console.log(`Added ${missingPsy.length} missing psys`); + const date = await getDateLatestArchived(); + //@ts-ignore + const dsAPIData = await getPsychologistList(date, "archived: true"); + if (dsAPIData.psychologists.length > 0) { + await updateState(dsAPIData.psychologists); + console.log(`${dsAPIData.psychologists.length} saved`); } - console.log(`importState done.`); + + console.log(`importArchived done.`); await logPsyNumber(); } catch (err) { Sentry.captureException(err); - console.error("ERROR importState: ", err); + console.error("ERROR importArchived: ", err); } }; +export const importFromDS = async (): Promise => { + await importData(); + await importArchived(); +}; + const validateDossier = async ( dossier: Psychologist, adeliData: AdeliData[] diff --git a/src/cron/launch.ts b/src/cron/launch.ts index 26f8fb52..6da2fac4 100644 --- a/src/cron/launch.ts +++ b/src/cron/launch.ts @@ -23,8 +23,7 @@ if (process.argv.length < 3) { } const cronJobs = { - importData: demarchesSimplifiees.importData, - importState: demarchesSimplifiees.importState, + importFromDS: demarchesSimplifiees.importFromDS, verifFolders: demarchesSimplifiees.verifFolders, }; diff --git a/src/db/seeds/psychologist.ts b/src/db/seeds/psychologist.ts index d6028d30..4b08eab8 100644 --- a/src/db/seeds/psychologist.ts +++ b/src/db/seeds/psychologist.ts @@ -70,7 +70,7 @@ export const getOnePsychologist = ( state: "accepte", teleconsultation: faker.datatype.boolean(), visible: true, - website: faker.helpers.randomize([ + website: faker.random.arrayElement([ faker.internet.domainName(), faker.internet.url(), ]), diff --git a/src/services/__tests__/ds-parse-psychologists.spec.ts b/src/services/__tests__/ds-parse-psychologists.spec.ts index 199e3d96..4224b62b 100644 --- a/src/services/__tests__/ds-parse-psychologists.spec.ts +++ b/src/services/__tests__/ds-parse-psychologists.spec.ts @@ -47,7 +47,7 @@ describe("parseDossierMetadata", () => { }); expect(axios.get).toHaveBeenCalledWith( - "https://api-adresse.data.gouv.fr/search/?q=12%20Rue%20Neuve%2031000%20Toulouse&limit=1" + "https://httpbin.org/apiAdresse/?q=12%20Rue%20Neuve%2031000%20Toulouse&limit=1" ); }); diff --git a/src/services/__tests__/psychologists.spec.ts b/src/services/__tests__/psychologists.spec.ts index f837bfe2..b03fb526 100644 --- a/src/services/__tests__/psychologists.spec.ts +++ b/src/services/__tests__/psychologists.spec.ts @@ -12,6 +12,8 @@ import { countAll, getAll, getByInstructor, + getDateLatestAccepte, + getDateLatestArchived, saveMany, update, updateState, @@ -68,6 +70,51 @@ describe("Service psychologists", () => { }); }); + describe("getDateLatestAccepte", () => { + async function insertInDbAsync(params) { + const latestAccepte = getOnePsychologist(params); + // @ts-ignore + return await models.Psychologist.create(latestAccepte); + } + + let latestAccepte, latestRefuse, latestAccepteArchived; + beforeEach(async () => { + latestAccepte = await insertInDbAsync({ + state: "accepte", + archived: false, + }); + latestRefuse = await insertInDbAsync({ + state: "refuse", + archived: true, + }); + latestAccepteArchived = await insertInDbAsync({ + state: "accepte", + archived: true, + }); + }); + it("validate test data", async () => { + expect(latestAccepte.getDataValue("createdAt")).not.toEqual( + latestRefuse.getDataValue("createdAt") + ); + expect(latestAccepteArchived.getDataValue("createdAt")).not.toEqual( + latestRefuse.getDataValue("createdAt") + ); + expect(latestAccepte.getDataValue("createdAt")).not.toEqual( + latestAccepteArchived.getDataValue("createdAt") + ); + }); + + it("should return the latest inserted psy", async () => { + const result = await getDateLatestAccepte(); + expect(result).toEqual(latestAccepte.getDataValue("createdAt")); + }); + + it("should return the latest archived psy", async () => { + const result = await getDateLatestArchived(); + expect(result).toEqual(latestAccepteArchived.getDataValue("createdAt")); + }); + }); + describe("countAll", () => { it("Should count non archived psychologists", async () => { const results = await countAll(); diff --git a/src/services/config.ts b/src/services/config.ts index 1d4d1027..55d0e2da 100644 --- a/src/services/config.ts +++ b/src/services/config.ts @@ -38,4 +38,5 @@ export default { url: process.env.DATABASE_URL || "", }, supportMail: process.env.SUPPORT_MAIL, + apiAdresseUrl: process.env.API_ADRESSE_URL, }; diff --git a/src/services/demarchesSimplifiees/buildRequest.ts b/src/services/demarchesSimplifiees/buildRequest.ts index d603d945..9fb779a4 100644 --- a/src/services/demarchesSimplifiees/buildRequest.ts +++ b/src/services/demarchesSimplifiees/buildRequest.ts @@ -25,7 +25,8 @@ export const requestPsychologistsState = async ( extraInfos?: string | undefined ): Promise => { const paginationCondition = getWhereConditionAfterCursor(afterCursor); - const query = gql`{ + const query = gql` +{ demarche (number: ${config.demarchesSimplifiees.id}) { id dossiers ${paginationCondition ? "(" + paginationCondition + ")" : ""} { @@ -40,20 +41,23 @@ export const requestPsychologistsState = async ( ${extraInfos ?? ""} } } - }}`; + } +} +`; return request(query); }; -export const requestPsychologistsAcceptes = async ( - afterCursor: string | undefined -): Promise => { - const paginationCondition = getWhereConditionAfterCursor(afterCursor); - const query = gql` +export const requestPsychologistsFor = + (date: Date, filter: string) => + async (afterCursor: string | undefined): Promise => { + const paginationCondition = getWhereConditionAfterCursor(afterCursor); + const dateFilter = date ? `updatedSince: "${date.toISOString()}"` : ""; + const query = gql` { demarche (number: ${config.demarchesSimplifiees.id}) { id - dossiers (state: ${DossierState.accepte}${paginationCondition}) { + dossiers (${filter}, ${dateFilter}${paginationCondition}) { pageInfo { hasNextPage endCursor @@ -87,8 +91,8 @@ export const requestPsychologistsAcceptes = async ( } `; - return request(query); -}; + return request(query); + }; export const requestPsychologistsById = async ( id: number @@ -119,7 +123,9 @@ export const requestPsychologistsById = async ( } } } - }`; + } + `; + return request(query); }; diff --git a/src/services/demarchesSimplifiees/import.ts b/src/services/demarchesSimplifiees/import.ts index 215243ec..addb8687 100644 --- a/src/services/demarchesSimplifiees/import.ts +++ b/src/services/demarchesSimplifiees/import.ts @@ -1,16 +1,11 @@ -import pLimit from "p-limit"; - import { DSResponse } from "../../types/demarcheSimplifiee"; import { DSPsychologist, Psychologist } from "../../types/psychologist"; import { requestDossiersWithAnnotations, - requestPsychologistsAcceptes, - requestPsychologistsById, - requestPsychologistsState, + requestPsychologistsFor, } from "./buildRequest"; import parsePsychologists from "./parse-psychologists"; -const limit = pLimit(5); export const getAllPsychologistList = async ( graphqlFunction: (string) => Promise, cursor: string | undefined = undefined, @@ -39,17 +34,17 @@ export const getAllPsychologistList = async ( }; export const getPsychologistList = async ( - cursor: string | undefined + date: Date, + filter: string ): Promise<{ psychologists: Psychologist[]; lastCursor: string; }> => { - const time = `Fetch all psychologists from DS (query id #${Math.random().toString()} with cursor ${cursor})`; + const time = `Fetch all psychologists from DS with ${filter} since ${date})`; console.time(time); const list = await getAllPsychologistList( - requestPsychologistsAcceptes, - cursor + requestPsychologistsFor(date, filter) ); const results = { lastCursor: list.lastCursor, @@ -60,38 +55,6 @@ export const getPsychologistList = async ( return results; }; -function fetchPsyById(ids: number[]) { - return Promise.all( - ids.map(async (id) => limit(() => requestPsychologistsById(id))) - ); -} - -function mapPsyData(psyData: any[]) { - return psyData.map((psy) => psy.dossier).flat(); -} - -export const getPsychologistFromListIds = async ( - ids: number[] -): Promise => { - const psyData = await fetchPsyById(ids); - return await parsePsychologists(mapPsyData(psyData)); -}; - -export const getPsychologistState = async (): Promise< - Partial[] -> => { - const time = `Fetch all psychologists state from DS (query id #${Math.random().toString()})`; - - console.time(time); - const list = await getAllPsychologistList(requestPsychologistsState); - console.timeEnd(time); - - return list.psychologists.map((dossier) => ({ - archived: dossier.archived, - id: dossier.number, - state: dossier.state, - })); -}; export const getDossiersInConstruction = async (): Promise< DSPsychologist[] > => { diff --git a/src/services/getAddressCoordinates.ts b/src/services/getAddressCoordinates.ts index abbec535..abf685c2 100644 --- a/src/services/getAddressCoordinates.ts +++ b/src/services/getAddressCoordinates.ts @@ -29,9 +29,8 @@ const getAddressCoordinates = async ( address: string ): Promise => { const firstAddress = address.split(ADDRESS_DELIMITER)[0]; - const url = encodeURI( - `https://api-adresse.data.gouv.fr/search/?q=${firstAddress}&limit=1` - ); + + const url = encodeURI(`${config.apiAdresseUrl}/?q=${firstAddress}&limit=1`); const response = await axios.get(url).catch(extractError); if (response && response?.data.features?.length > 0) { diff --git a/src/services/psychologists.ts b/src/services/psychologists.ts index a670c31d..47c55a0d 100644 --- a/src/services/psychologists.ts +++ b/src/services/psychologists.ts @@ -18,6 +18,21 @@ export const getOne = async (id: string): Promise => { }); }; +const getDateLatestFor = async (where): Promise => { + const psy = await models.Psychologist.findOne({ + attributes: ["created_at", "archived", "state"], + order: [["created_at", "DESC"]], + where: where, + }); + // @ts-ignore + return psy?.dataValues?.created_at; +}; +export const getDateLatestAccepte = async (): Promise => + getDateLatestFor({ state: "accepte", archived: false }); + +export const getDateLatestArchived = async (): Promise => + getDateLatestFor({ archived: true }); + export const getByInstructor = async ( group: string ): Promise => { @@ -94,7 +109,7 @@ export const getAll = async (filters: { export const saveMany = async (psychologists: Psychologist[]) => { //@ts-ignore return models.Psychologist.bulkCreate(psychologists, { - updateOnDuplicate: ["id"], + ignoreDuplicates: true, }); }; @@ -158,16 +173,3 @@ export const updateState = async (newStates: Partial[]) => { ) ); }; - -export const filterIdsNotInDb = async (psy): Promise => { - // @ts-ignore - const psyInDb: { id: number }[] = await models.Psychologist.findAll({ - attributes: ["id"], - raw: true, - where: { state: "accepte" }, - }); - - return psy - .filter((psy) => !psyInDb.find((fromDb) => psy.id === fromDb.id)) - .map((psy) => psy.id); -}; From 54767332db097f89164bbf9de749671cf605a6e4 Mon Sep 17 00:00:00 2001 From: Social Groovy Bot <45039513+SocialGroovyBot@users.noreply.github.com> Date: Tue, 10 May 2022 12:34:25 +0000 Subject: [PATCH 2/2] chore(release): version 1.32.0 # [1.32.0](https://github.com/SocialGouv/mon-psy-sante/compare/v1.31.1...v1.32.0) (2022-05-10) ### Features * **cron:** fetch data from DS in one cron, and using the latest updated dossier date ([#159](https://github.com/SocialGouv/mon-psy-sante/issues/159)) ([1ab0a23](https://github.com/SocialGouv/mon-psy-sante/commit/1ab0a239c79b447f03b375bdcefe69906b9d0839)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfa944ca..ff89a3b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# [1.32.0](https://github.com/SocialGouv/mon-psy-sante/compare/v1.31.1...v1.32.0) (2022-05-10) + + +### Features + +* **cron:** fetch data from DS in one cron, and using the latest updated dossier date ([#159](https://github.com/SocialGouv/mon-psy-sante/issues/159)) ([1ab0a23](https://github.com/SocialGouv/mon-psy-sante/commit/1ab0a239c79b447f03b375bdcefe69906b9d0839)) + ## [1.31.1](https://github.com/SocialGouv/mon-psy-sante/compare/v1.31.0...v1.31.1) (2022-05-06) diff --git a/package.json b/package.json index f7859f25..8d39c61b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "monpsy", - "version": "1.31.1", + "version": "1.32.0", "commitlint": { "extends": [ "@commitlint/config-conventional"