Untitled
async getAgentDetailId(id: number) { Agent.hasOne(Officeagent, {sourceKey: 'office_id', foreignKey: 'id'}); let agent = await Agent.findOne({ where: {id: id}, include: [Officeagent], attributes: { exclude: ['quota'] }, }); const sqlQueryGettype = ` Select building_type_id, agent_id from advertises where advertises.agent_id = ` + id + ` group by building_type_id, agent_id `; let building: string | any[] = [] // @ts-ignore await sequelize.query(sqlQueryGettype, {type: Sequelize.QueryTypes.SELECT}) .then((results: string | any[]) => { // Handle the query results here building = results }) let specialis: string | any[] = [] for (let i = 0; i < building.length; i++) { let sqlQueryGetads = ` Select building_types.* from building_types where id = '` + building[i]['building_type_id'] + `' `; // @ts-ignore await sequelize.query(sqlQueryGetads, {type: Sequelize.QueryTypes.SELECT}) .then((results: [undefined, number]) => { // Handle the query results here // @ts-ignore specialis.push(results); }) } const sqlQueryGetArea = ` Select regency from advertises where agent_id = ` + id + ` and regency is not null and subdistrict is not null and province is not null group by regency `; let area: string | any[] = [] // @ts-ignore await sequelize.query(sqlQueryGetArea, {type: Sequelize.QueryTypes.SELECT}) .then((results: string | any[]) => { // Handle the query results here area = results }) let spesial = specialis[0] || [] return {agent: agent, specialis: spesial, area: area} }
Leave a Comment