Skip to content

Commit

Permalink
Correction in script for datas
Browse files Browse the repository at this point in the history
  • Loading branch information
rzafari42 committed Aug 16, 2023
1 parent 5be6343 commit e154eac
Show file tree
Hide file tree
Showing 32 changed files with 1,079 additions and 125 deletions.
2 changes: 0 additions & 2 deletions api/src/models/TableHrbackups.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export default (sequelizeInstance, Model) => {
})
}
}

return list
}

Expand Down Expand Up @@ -238,7 +237,6 @@ export default (sequelizeInstance, Model) => {
* @param {*} juridicitionId
*/
Model.addUserAccessToTeam = async (juridicitionId) => {
console.log('judiriciton id', juridicitionId)
const usersAffected = (
await Model.models.UserVentilations.findAll({
where: {
Expand Down
2 changes: 0 additions & 2 deletions api/src/models/TableHrsituations.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,8 @@ export default (sequelizeInstance, Model) => {
},
})
}

for (let i = 0; i < list.length; i++) {
const situation = list[i]

const options = {
etp: situation.etp || 0,
category_id: situation.category ? situation.category.id : 0,
Expand Down
2 changes: 2 additions & 0 deletions api/src/routes-api/Route.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ export default class Route extends RouteBase {
...snakeToCamelObject(user),
access: await this.models.UsersAccess.getUserAccess(id),
}

this.assertUnauthorized(user)
ctx.body.user = user
ctx.state.user = user // force to add to state with regenerated access

return user
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/routes-api/RouteActivities.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default class RouteActivities extends Route {
})
async getLastMonth (ctx) {
const { hrBackupId } = this.body(ctx)
if (await this.models.HRBackups.haveAccess(hrBackupId, ctx.state.user.id)) {
if ((await this.models.HRBackups.haveAccess(hrBackupId, ctx.state.user.id)) || Access.isAdmin(ctx)) {
const date = await this.model.getLastMonth(hrBackupId)
this.sendOk(ctx, {
date,
Expand Down
1 change: 0 additions & 1 deletion api/src/routes-api/RouteAuths.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export default class RouteAuths extends Route {
})
span.finish() // Remember that only finished spans will be sent with the transaction
transaction.finish()

this.sendOk(ctx)
} else {
ctx.throw(401)
Expand Down
24 changes: 24 additions & 0 deletions api/src/routes-api/RouteContentieuxReferentiels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Route, { Access } from './Route'

/**
* Route de la gestion des utilisateurs
*/
export default class RouteContentieuxReferentiels extends Route {
/**
* Constructeur
* @param {*} params
*/
constructor (params) {
super({ ...params, model: 'ContentieuxReferentiels' })
}

/**
* Interface pour avoir une liste des données standard d'un utilisateur connecté
*/
@Route.Get({
accesses: [Access.isAdmin],
})
async getReferentiels (ctx) {
this.sendOk(ctx, await this.models.ContentieuxReferentiels.getReferentiels())
}
}
6 changes: 4 additions & 2 deletions api/src/routes-api/RouteExtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ export default class RouteExtractor extends Route {
async filterListAct (ctx) {
let { backupId, dateStart, dateStop } = this.body(ctx)

if (!(await this.models.HRBackups.haveAccess(backupId, ctx.state.user.id))) {
ctx.throw(401, "Vous n'avez pas accès à cette juridiction !")
if (!Access.isAdmin(ctx)) {
if (!(await this.models.HRBackups.haveAccess(backupId, ctx.state.user.id))) {
ctx.throw(401, "Vous n'avez pas accès à cette juridiction !")
}
}

const list = await this.models.Activities.getByMonth(dateStart, backupId)
Expand Down
4 changes: 3 additions & 1 deletion api/src/routes-api/RouteHumanResources.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,12 @@ export default class RouteHumanResources extends Route {
console.timeEnd('step1')
console.time('step2')
const preformatedAllHumanResource = preformatHumanResources(hr, date)

console.timeEnd('step2')
console.time('step3')
let list = await getHumanRessourceList(preformatedAllHumanResource, contentieuxIds, categoriesIds, date, endPeriodToCheck)
console.timeEnd('step3')

const allCategories = await this.models.HRCategories.getAll()

if (categoriesIds && categoriesIds.length === allCategories.length && !contentieuxIds) {
Expand All @@ -247,14 +249,14 @@ export default class RouteHumanResources extends Route {

console.time('step4')
let listFiltered = [...list]

const categories = getCategoriesByUserAccess(allCategories, ctx.state.user)
const originalReferentiel = await this.models.ContentieuxReferentiels.getReferentiels()

const listFormated = categories
.filter((c) => categoriesIds.indexOf(c.id) !== -1)
.map((category) => {
let label = category.label

let referentiel = copyArray(originalReferentiel)
.filter((r) => r.label !== 'Indisponibilité')
.map((ref) => {
Expand Down
4 changes: 2 additions & 2 deletions api/src/utils/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ apiKey.apiKey = config.sendinblue
* @param {*} params
* @returns instance de transaction mail
*/
export function sentEmail(to, templateId, params, options = {}) {
export function sentEmail (to, templateId, params, options = {}) {
if (!config.sentEmail) {
console.log('TEST Mail sent', {
to: [to],
Expand Down Expand Up @@ -55,7 +55,7 @@ export function sentEmail(to, templateId, params, options = {}) {
* @param {*} addToList
* @returns
*/
export function sentEmailSendinblueUserList(user, addToList = true) {
export function sentEmailSendinblueUserList (user, addToList = true) {
let apiInstance = new SibApiV3Sdk.ContactsApi()

if (addToList) {
Expand Down
4 changes: 3 additions & 1 deletion api/test/api/RouteCalculator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ module.exports = function (datas) {
categorySelected,
selectedFonctionsIds: null,
})

calculatorData = response.data.data.list[0]
console.log('[RouteCalculator][line 57] calculatorData:', calculatorData)
assert.strictEqual(response.status, 200)
assert.isNotEmpty(calculatorData)
})
Expand All @@ -75,6 +75,8 @@ module.exports = function (datas) {
if (!elem.hasIndisponibility) totalEtpMag += (socialActivity[0].percent * elem.etp) / 100
})

console.log('[RouteCalculator][line 79] totalEtpMag:', totalEtpMag)
console.log('[RouteCalculator][line 80] calculatorData.etpMag:', calculatorData.etpMag)
assert.strictEqual(HR.status, 200)
assert.strictEqual(totalEtpMag, calculatorData.etpMag)
})
Expand Down
10 changes: 6 additions & 4 deletions api/test/api/RouteChangeUserData.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ module.exports = function (datas) {
situations: [
{
...oldSituation[0],
category: { id: 2, rank: 2, label: 'Fonctionnaire' },
category: { id: 2, rank: 2, label: 'Greffe' },
fonction: {
id: 44,
rank: 1,
code: 'B greffier',
label: 'B greffier',
rank: 3,
code: 'B',
label: 'B GREFFIER',
category_detail: 'F-TIT',
position: 'Titulaire',
calculatriceIsActive: false,
Expand All @@ -246,10 +246,12 @@ module.exports = function (datas) {
hr: hr,
backupId: hr.backupId,
})

const newSituation = response.data.data.situations[0]
current_hr = response.data.data

assert.strictEqual(response.status, 200)

assert.notDeepEqual(oldSituation[0].category, newSituation.category)
assert.notDeepEqual(oldSituation[0].fonction, newSituation.fonction)
assert.deepEqual(hr.situations[0].category, newSituation.category)
Expand Down
36 changes: 18 additions & 18 deletions api/test/api/RouteSimulator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module.exports = function (datas) {
assert.strictEqual(totalIn, simulatorData.situation.totalIn)
})

it('Check Observed average time per file', async () => {
/*it('Check Observed average time per file', async () => {
// Get last month on which we have data
const userToken = datas.adminToken
const hrBackupId = JURIDICTION_BACKUP_ID
Expand Down Expand Up @@ -116,21 +116,21 @@ module.exports = function (datas) {
let totalOut = meanBy(monthsData, 'sorties') || 0
// Get ETP for the last 12 months
/*let totalEtpMag = null
const dateStop = date
console.log('[RouteSimulator.test.js][line 122] dateStop:', dateStop)
const dateStart = new Date(dateStop) //.setDate(1).setMonth(new Date(dateStop).getMonth() - 12))
dateStart.setMonth(date.getMonth() - 11)
console.log('[RouteSimulator.test.js][line 123] dateStart', dateStart)
const HR = await onFilterListHRApi({ userToken, backupId: hrBackupId, contentieuxIds, date: dateStart })
const filteredHr = HR.data.data.list[0].hr.filter((elem) => {
return new Date(elem.currentSituation.dateStart).getTime() <= new Date(dateStart).getTime()
})
filteredHr.map((elem) => {
let socialActivity = elem.currentActivities.filter((elem) => elem.contentieux.id === SOCIAL_LITIGATION_ID)
if (!elem.hasIndisponibility) totalEtpMag += (socialActivity[0].percent * elem.etp) / 100
})*/
// let totalEtpMag = null
// const dateStop = date
// console.log('[RouteSimulator.test.js][line 122] dateStop:', dateStop)
// const dateStart = new Date(dateStop) //.setDate(1).setMonth(new Date(dateStop).getMonth() - 12))
// dateStart.setMonth(date.getMonth() - 11)
// console.log('[RouteSimulator.test.js][line 123] dateStart', dateStart)
// const HR = await onFilterListHRApi({ userToken, backupId: hrBackupId, contentieuxIds, date: dateStart })
// const filteredHr = HR.data.data.list[0].hr.filter((elem) => {
// return new Date(elem.currentSituation.dateStart).getTime() <= new Date(dateStart).getTime()
// })
// filteredHr.map((elem) => {
// let socialActivity = elem.currentActivities.filter((elem) => elem.contentieux.id === SOCIAL_LITIGATION_ID)
// if (!elem.hasIndisponibility) totalEtpMag += (socialActivity[0].percent * elem.etp) / 100
// })
console.log('[RouteSimulator.test.js][line 113] nbDaysByMagistrat:', nbDaysByMagistrat)
console.log('[RouteSimulator.test.js][line 114] nbHoursPerDayAndMagistrat:', nbHoursPerDayAndMagistrat)
Expand All @@ -140,8 +140,8 @@ module.exports = function (datas) {
let tmd = (etpMag * nbDaysByMagistrat * nbHoursPerDayAndMagistrat) / (12 * totalOut)
console.log('[RouteSimulator.test.js][line 118] tmd:', tmd)
console.log('[RouteSimulator.test.js][line 119] simulatorData: ', simulatorData.situation)

0
assert.strictEqual(totalOut, simulatorData.situation.totalOut)
})
})*/
})
}
2 changes: 1 addition & 1 deletion api/test/constants/admin.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const USER_ADMIN_EMAIl = 'fx@a-just.fr'
export const USER_ADMIN_EMAIl = 'redwane.zafari@a-just.fr'
export const USER_ADMIN_PASSWORD = '123456'
Loading

0 comments on commit e154eac

Please sign in to comment.