Skip to content

Commit

Permalink
fix: updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kevbarns committed Jun 26, 2024
1 parent 15b7723 commit a1d3107
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { zRoutes } from "shared/index"

import { getDbCollection } from "@/common/utils/mongodbUtils"

import * as eligibleTrainingsForAppointmentService from "../../../services/eligibleTrainingsForAppointment.service"
import { Server } from "../../server"

/**
Expand Down Expand Up @@ -54,7 +53,7 @@ export default (server: Server) => {
}
}
}
const result = await eligibleTrainingsForAppointmentService.updateParameter(new ObjectId(params.id), body)
const result = await getDbCollection("eligible_trainings_for_appointments").findOneAndUpdate(new ObjectId(params.id), { $set: { body } }, { returnDocument: "after" })

res.send(result)
}
Expand Down
4 changes: 2 additions & 2 deletions server/src/http/controllers/etablissement.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export default (server: Server) => {
eligibleTrainingsForAppointmentService.findOneAndUpdate(
{ _id: eligibleTrainingsForAppointment._id, lieu_formation_email: { $nin: [null, ""] } },
{
referrers: [...new Set([...eligibleTrainingsForAppointment.referrers, referrers.AFFELNET.name])],
$set: { referrers: [...new Set([...eligibleTrainingsForAppointment.referrers, referrers.AFFELNET.name])] },
}
)
),
Expand Down Expand Up @@ -236,7 +236,7 @@ export default (server: Server) => {
eligibleTrainingsForAppointmentService.findOneAndUpdate(
{ _id: eligibleTrainingsForAppointment._id, lieu_formation_email: { $nin: [null, ""] } },
{
referrers: [...new Set([...eligibleTrainingsForAppointment.referrers, referrers.PARCOURSUP.name])],
$set: { referrers: [...new Set([...eligibleTrainingsForAppointment.referrers, referrers.PARCOURSUP.name])] },
}
)
),
Expand Down
2 changes: 1 addition & 1 deletion server/src/jobs/lba_recruteur/api/disableApiUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { logger } from "../../../common/logger"
import { getDbCollection } from "../../../common/utils/mongodbUtils"

export const disableApiUser = async (email: ICredential["email"], state: ICredential["actif"] = false) => {
const updatedUser = await getDbCollection("credentials").findOneAndUpdate({ email }, { actif: state }, { returnDocument: "after" })
const updatedUser = await getDbCollection("credentials").findOneAndUpdate({ email }, { $set: { actif: state } }, { returnDocument: "after" })

logger.info(`User ${updatedUser?.email} disabled — API state : ${updatedUser?.actif}`)
}
2 changes: 1 addition & 1 deletion server/src/jobs/lba_recruteur/api/resetApiKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import { logger } from "../../../common/logger"
import { getDbCollection } from "../../../common/utils/mongodbUtils"

export const resetApiKey = async (email) => {
const updatedUser = await getDbCollection("credentials").findOneAndUpdate({ email }, { api_key: `mna-${randomUUID()}` }, { returnDocument: "after" })
const updatedUser = await getDbCollection("credentials").findOneAndUpdate({ email }, { $set: { api_key: `mna-${randomUUID()}` } }, { returnDocument: "after" })
logger.info(`API-KEY : ${updatedUser?.api_key}`)
}
42 changes: 22 additions & 20 deletions server/src/jobs/rdv/syncEtablissementsAndFormations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { referrers } from "shared/constants/referers"
import { getDbCollection } from "@/common/utils/mongodbUtils"

import { logger } from "../../common/logger"
import { create, getEmailForRdv, updateParameter } from "../../services/eligibleTrainingsForAppointment.service"
import { create, getEmailForRdv } from "../../services/eligibleTrainingsForAppointment.service"
import { findFirstNonBlacklistedEmail } from "../../services/formation.service"

const hasDateProperty = (etablissements, propertyName) => {
Expand Down Expand Up @@ -96,25 +96,27 @@ export const syncEtablissementsAndFormations = async () => {
})
}

await updateParameter(eligibleTrainingsForAppointment._id, {
training_id_catalogue: formation._id,
lieu_formation_email: emailRdv,
parcoursup_id: formation.parcoursup_id,
parcoursup_visible: formation.parcoursup_visible,
affelnet_visible: formation.affelnet_visible,
training_code_formation_diplome: formation.cfd,
etablissement_formateur_zip_code: formation.etablissement_formateur_code_postal,
training_intitule_long: formation.intitule_long,
referrers: referrersToActivate,
is_catalogue_published: formation.published,
last_catalogue_sync_date: new Date(),
lieu_formation_street: formation.lieu_formation_adresse,
lieu_formation_city: formation.localite,
lieu_formation_zip_code: formation.code_postal,
etablissement_formateur_raison_sociale: formation.etablissement_formateur_entreprise_raison_sociale,
etablissement_formateur_street: formation.etablissement_formateur_adresse,
departement_etablissement_formateur: formation.etablissement_formateur_nom_departement,
etablissement_formateur_city: formation.etablissement_formateur_localite,
await getDbCollection("eligible_trainings_for_appointments").updateOne(eligibleTrainingsForAppointment._id, {
$set: {
training_id_catalogue: formation._id,
lieu_formation_email: emailRdv,
parcoursup_id: formation.parcoursup_id,
parcoursup_visible: formation.parcoursup_visible,
affelnet_visible: formation.affelnet_visible,
training_code_formation_diplome: formation.cfd,
etablissement_formateur_zip_code: formation.etablissement_formateur_code_postal,
training_intitule_long: formation.intitule_long,
referrers: referrersToActivate,
is_catalogue_published: formation.published,
last_catalogue_sync_date: new Date(),
lieu_formation_street: formation.lieu_formation_adresse,
lieu_formation_city: formation.localite,
lieu_formation_zip_code: formation.code_postal,
etablissement_formateur_raison_sociale: formation.etablissement_formateur_entreprise_raison_sociale,
etablissement_formateur_street: formation.etablissement_formateur_adresse,
departement_etablissement_formateur: formation.etablissement_formateur_nom_departement,
etablissement_formateur_city: formation.etablissement_formateur_localite,
},
})
} else {
const emailRdv = await getEmailForRdv({
Expand Down
8 changes: 5 additions & 3 deletions server/src/services/application.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ export const addEmailToBlacklist = async (email: string, blacklistingOrigin: str
await getDbCollection("emailblacklists").findOneAndUpdate(
{ email },
{
email,
blacklisting_origin: blacklistingOrigin,
$setOnInsert: { _id: new ObjectId(), created_at: new Date() },
$set: {
email,
blacklisting_origin: blacklistingOrigin,
$setOnInsert: { _id: new ObjectId(), created_at: new Date() },
},
},
{ upsert: true }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const disableEligibleTraininForAppointmentWithEmail = async (disabledEmai

await Promise.all(
eligibleTrainingsForAppointmentsWithEmail.map(async (eligibleTrainingsForAppointment) => {
await getDbCollection("eligible_trainings_for_appointments").updateOne({ _id: eligibleTrainingsForAppointment._id }, { referrers: [], lieu_formation_email: "" })
await getDbCollection("eligible_trainings_for_appointments").updateOne({ _id: eligibleTrainingsForAppointment._id }, { $set: { referrers: [], lieu_formation_email: "" } })

logger.info('Eligible training disabled for "hard_bounce" reason', {
eligibleTrainingsForAppointmentId: eligibleTrainingsForAppointment._id,
Expand Down
2 changes: 1 addition & 1 deletion server/src/services/formulaire.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ export const archiveDelegatedFormulaire = async (siret: IUserRecruteur["establis
job.job_status = JOB_STATUS.ANNULEE
})

await getDbCollection("recruiters").findOneAndUpdate(form._id, { ...form, updatedAt: new Date() })
await getDbCollection("recruiters").findOneAndUpdate(form._id, { $set: { ...form, updatedAt: new Date() } })
})

return true
Expand Down
2 changes: 1 addition & 1 deletion server/src/services/opco.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const getOpcoBySirenFromDB = async (siren: string) => {
* @param {IOpco} opcoData
* @returns {Promise<IOpco>}
*/
export const saveOpco = async (opcoData: Omit<IOpco, "_id">) => getDbCollection("opcos").findOneAndUpdate({ siren: opcoData.siren }, opcoData, { upsert: true })
export const saveOpco = async (opcoData: Omit<IOpco, "_id">) => getDbCollection("opcos").findOneAndUpdate({ siren: opcoData.siren }, { $set: opcoData }, { upsert: true })

/**
* @description retourne le nom court d'un opco en paramètre
Expand Down

0 comments on commit a1d3107

Please sign in to comment.