Skip to content

Commit

Permalink
Merge branch 'sandbox' of https://github.com/betagouv/a-just into san…
Browse files Browse the repository at this point in the history
…dbox
  • Loading branch information
MrJimmyChevallier committed Aug 29, 2023
2 parents 9a09a70 + 218fe1e commit c8a41c4
Show file tree
Hide file tree
Showing 13 changed files with 266 additions and 37 deletions.
4 changes: 4 additions & 0 deletions api/config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ module.exports = {
* Sent Email
*/
sentEmail: true,
/**
* Juridiction type
*/
juridictionType: process.env.TYPE_ID || 0,
/**
* Token expiration delay
*/
Expand Down
4 changes: 3 additions & 1 deletion api/src/models/TableHrbackups.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ export default (sequelizeInstance, Model) => {
})
}
}

//console.log('\n\n\n\n\n\n\n\n\n\n\n\nLIST:', list)
//list.map((elem) => console.log('id:', elem.id, ' | label:', elem.label))
//console.log('\n\n\n\n\n\n\n\n\n\n\n\n')
return list
}

Expand Down
5 changes: 4 additions & 1 deletion api/src/models/TableUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default (sequelizeInstance, Model) => {
*/
Model.tryConnection = async (email, password, roles) => {
email = (email || '').toLowerCase()

console.log('[tableUsers.js][line 22] email:', email)
const cleanUser = async (user) => {
await user.update({
nb_try_connection: null,
Expand All @@ -29,12 +29,15 @@ export default (sequelizeInstance, Model) => {
user.dataValues.first_try_connection = null
return user
}
console.log('[tableUsers.js][line 32] roles:', roles)

let user = await Model.findOne({ where: { email, role: roles } })
console.log('[tableUsers.js][line 35] user:', user)
if (user) {
if (user.dataValues.status === 0) {
return "Votre compte n'est plus accessible."
}
console.log('user:', user.dataValues)

if (user.dataValues.first_try_connection) {
const now = new Date()
Expand Down
5 changes: 4 additions & 1 deletion api/src/routes-api/RouteAuths.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ export default class RouteAuths extends Route {
})
async login (ctx) {
const { password, email } = this.body(ctx)

console.log('[RouteAuths.js][line 32] email: |', email, '|')
console.log('[RouteAuths.js][line 33] password: |', password, '|')
const tryUserCon = await this.model.tryConnection(email, password, [0, null, USER_ROLE_TEAM, USER_ROLE_ADMIN, USER_ROLE_SUPER_ADMIN])
console.log('[RouteAuths.js][line 35] tryUserCon: |', tryUserCon, '|')
if (typeof tryUserCon === 'string') {
ctx.throw(401, tryUserCon)
} else {
Expand Down Expand Up @@ -58,6 +60,7 @@ export default class RouteAuths extends Route {
const { password, email } = this.body(ctx)

const tryUserCon = await this.model.tryConnection(email, password, [USER_ROLE_ADMIN, USER_ROLE_SUPER_ADMIN])
console.log('tryUserCon:')
if (typeof tryUserCon === 'string') {
ctx.throw(401, tryUserCon)
} else {
Expand Down
125 changes: 125 additions & 0 deletions api/src/routes-api/RouteExtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,131 @@ export default class RouteExtractor extends Route {
})
}

/**
*
* @param {*} dateStart
* @param {*} dateStop
*
*/
@Route.Post({
bodyType: Types.object().keys({
dateStart: Types.date().required(),
dateStop: Types.date().required(),
}),
accesses: [Access.canVewHR],
})
async juridictionAjustedDataList (ctx) {
let { dateStart /*, dateStop */ } = this.body(ctx)
let result = []

await this.models.HRBackups.getAll()
.then(async (res) => {
res.map(async (elem) => {
await this.models.Activities.getByMonth(dateStart, elem.id)
.then(
(res) => {
if (res.length) {
console.log('\n\n\n\n\n\n\n\nTj name data: ', elem.label, ' | id: ', res[0].backupId, 'TJ Data:', res, '\n\n\n\n\n\n\n\n')
//console.log('res.length:', res.length)
for (let i = 0; i < res.length; i++) {
//console.log('res[i]:', res[i])
if (res[i].entrees !== null || res[i].sorties !== null || res[i].stock !== null) {
console.log('Is not null tj=', elem.label)
result.push({ label: elem.label, id: res[0].backupId })
break
}
}
}

//result.push({ label: tjLabel, id: tjId })
} //console.log('\n\n\n\n\n\n\n\nTj name data: ', tjLabel, ' | id: ', tjId, 'TJ Data:', res, '\n\n\n\n\n\n\n\n')
)
.catch((err) => console.log('error: ', err))
}, console.log('\n\n\n\n\n\n\n\nresult01:', result, '\n\n\n\n\n\n\n\n'))
})
.then((res) => {
console.log('\n\n\n\n\n\n\n\nHere:')
console.log('res:', res)
console.log('result final:', result, '\n\n\n\n\n\n\n\n')
})

// console.log('\n\n\n\n\n\n\n\nResult00:', list, '\n\n\n\n\n\n\n\n')
/*list.map(async (elem) => {
await this.models.Activities.getByMonth(dateStart, elem.id)
.then(
(res) => {
const tjId = elem.id
const tjLabel = elem.label
//console.log('res:', res)
if (res.length) {
console.log('\n\n\n\n\n\n\n\nTj name data: ', tjLabel, ' | id: ', res[0].backupId, 'TJ Data:', res, '\n\n\n\n\n\n\n\n')
//console.log('res.length:', res.length)
for (let i = 0; i < res.length; i++) {
//console.log('res[i]:', res[i])
if (res[i].entrees !== null || res[i].sorties !== null || res[i].stock !== null) {
console.log('Is not null tj=', tjLabel)
result.push({ label: tjLabel, id: res[0].backupId })
break
}
}
}
//console.log('\n\n\n\n\n\n\n\nresult01:', result, '\n\n\n\n\n\n\n\n')
//result.push({ label: tjLabel, id: tjId })
} //console.log('\n\n\n\n\n\n\n\nTj name data: ', tjLabel, ' | id: ', tjId, 'TJ Data:', res, '\n\n\n\n\n\n\n\n')
)
.catch((err) => console.log('error: ', err))
})*/
//console.log('\n\n\n\n\n\n\n\nresult final:', result, '\n\n\n\n\n\n\n\n')

/*list.map(async (tj) => {
const label = tj.label
const id = tj.id
console.log('TJ label:', tj.label)
console.log('TJ id:', tj.id)
await this.models.Activities.getByMonth(dateStart, tj.id)
.then(
(res) => {
console.log('label:', label)
console.log('id:', id)
const tjId = tj.id
const tjLabel = tj.label
console.log('TJ name01:', tjLabel, ' | TJ id01: ', tjId)
console.log('res:', res)
console.log('res.length:', res.length)
if (res.length) {
console.log('\n\n\n\n\n\n\n\nTj name data: ', tjLabel, ' | id: ', tjId, 'TJ Data:', res, '\n\n\n\n\n\n\n\n')
//console.log('res.length:', res.length)
for (let i = 0; i < res.length; i++) {
//console.log('res[i]:', res[i])
if (res[i].entrees !== null || res[i].sorties !== null || res[i].stock !== null) {
console.log('Is not null tj=', tjLabel)
result.push({ label: tjLabel, id: tjId })
break
}
}
}
//console.log('\n\n\n\n\n\n\n\nresult01:', result, '\n\n\n\n\n\n\n\n')
//result.push({ label: tjLabel, id: tjId })
} //console.log('\n\n\n\n\n\n\n\nTj name data: ', tjLabel, ' | id: ', tjId, 'TJ Data:', res, '\n\n\n\n\n\n\n\n')
)
.catch((err) => console.log('error: ', err))
console.log('\n\n\n\n\n\n\n\nresult00:', result, '\n\n\n\n\n\n\n\n')
})*/
/*.then(() => {
console.log('result00:', result)
this.sendOk(ctx, { list: result })
})*/
}

@Route.Post({
bodyType: Types.object().keys({
backupId: Types.number().required(),
Expand Down
3 changes: 1 addition & 2 deletions api/src/routes-api/RouteUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class RouteUsers extends Route {
}
}

/**
/**
* Interface qui retourne le process.env
*/
@Route.Get()
Expand Down Expand Up @@ -203,7 +203,6 @@ export default class RouteUsers extends Route {
if (userToUpdate && userToUpdate.role === USER_ROLE_SUPER_ADMIN && ctx.state.user.role !== USER_ROLE_SUPER_ADMIN) {
ctx.throw(401, "Vous ne pouvez pas modifier les droits d'un super administrateur.")
}

try {
await this.model.updateAccount(this.body(ctx))
await this.models.Logs.addLog(ADMIN_CHANGE_USER_ACCESS, ctx.state.user.id, { userId })
Expand Down
Loading

0 comments on commit c8a41c4

Please sign in to comment.