api in groups + agents types & sprites
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { authGuard } from '../authGuard.js'
|
||||
|
||||
export const mappings = [
|
||||
{ method: 'get', url:'/agent-types', handler: 'getAgentTypes', middlewares: [authGuard]},
|
||||
{ method: 'get', url:'/agent-sprites/:group', handler: 'getAgentSprites', middlewares: [authGuard]},
|
||||
]
|
||||
|
||||
export const methods = {
|
||||
async getAgentTypes(req, res) {
|
||||
let results
|
||||
if(req.params.family){
|
||||
results = await this.db.execute(`
|
||||
SELECT *
|
||||
FROM p42SIM.agent_types
|
||||
WHERE atp_fam_name = ?
|
||||
`, [req.params.family])
|
||||
|
||||
} else {
|
||||
results = await this.db.execute(`SELECT * FROM p42SIM.agent_types`, [])
|
||||
}
|
||||
|
||||
this.ok(req, res, {
|
||||
agentTypes : results
|
||||
})
|
||||
},
|
||||
|
||||
async getAgentSprites(req, res) {
|
||||
const results = await this.db.execute(`
|
||||
SELECT *
|
||||
FROM p42SIM.agent_types
|
||||
LEFT JOIN p42GUI.agents_sprites on asp_atp_id = atp_id
|
||||
WHERE asp_group = ?`, [req.params.group])
|
||||
const fullObj = {}
|
||||
for(const row of results){
|
||||
fullObj[row.atp_name] = row.asp_3d
|
||||
}
|
||||
this.ok(req, res, {
|
||||
agentSprites: fullObj
|
||||
})
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user