28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
import AppDataSource from "@/app/_data/source/app-data-source";
|
|
|
|
export async function assignUser(category_of_complaint :string) {
|
|
const connection_mantis = await AppDataSource.getMantisConnection();
|
|
let assign_team_id,random_assignee;
|
|
if(category_of_complaint === 'ATM Related'){
|
|
assign_team_id = 12 ;
|
|
}
|
|
if(category_of_complaint === 'Internet Banking'){
|
|
assign_team_id = 13 ;
|
|
}
|
|
if(category_of_complaint === 'Mobile Banking'){
|
|
assign_team_id = 14 ;
|
|
}
|
|
if(category_of_complaint === 'Others'){
|
|
assign_team_id = 15 ;
|
|
}
|
|
const queryRunner = connection_mantis.createQueryRunner();
|
|
await queryRunner.connect();
|
|
const query = await queryRunner.query('SELECT id,username FROM "kccb_user" WHERE access_level = $1', [assign_team_id]);
|
|
if(query.length == 0)
|
|
random_assignee = 1 ;
|
|
else{
|
|
const team_list =query.map((row: { id: any; }) =>row.id)
|
|
random_assignee = team_list[Math.floor(Math.random()* team_list.length)]
|
|
}
|
|
return random_assignee;
|
|
} |