Node.js
5
Вклад в тег
async getProjectStates(project_id) {
const states = await State.findAll({
where: {
project_id
},
order: [
['serial_number', 'ASC']
]
})
let statesDto = []
if (states.length) {
await Promise.all(states.map(async state => {
const tasks = await Task.findAll({
where: {
state_id: state.id
},
order: [
['createdAt', 'DESC']
]
})
let tasksDto = []
if (tasks.length) {
tasks.map(task => {
const taskDto = new TaskDto(task)
tasksDto.push(taskDto)
})
}
const stateDto = new StateDto(state)
stateDto.tasks = tasksDto
statesDto.push(stateDto)
}))
}
return statesDto
}
const arr = []
console.log(Boolean(arr)) // true
require('dotenv').config({ path: './.env'})
if (!msg.isChat) return