Add API documentation for TrackGo HTTP API and enhance employee management features

- Created a new `api.md` file detailing the TrackGo HTTP API, including authentication, user management, and employee operations.
- Updated `Employee` type to simplify user relation handling by replacing `UserRelation` with a more concise structure.
- Enhanced filtering capabilities in employee queries to support an array of positions.
- Refactored employee-related services and repositories to accommodate the new position filtering logic.
- Added unit and e2e tests to validate the new API documentation and employee management functionalities.
This commit is contained in:
shancheas
2026-08-27 15:07:20 +07:00
parent 4c45a4371e
commit 627aeac4a0
13 changed files with 270 additions and 47 deletions
+54
View File
@@ -202,6 +202,60 @@ describe('Employees (e2e)', () => {
.expect(204);
});
it('lists employees filtered by an array of positions', async () => {
const suffix = Date.now().toString().slice(-6);
const auth = { Authorization: `Bearer ${adminAccessToken}` };
const base = {
name: 'Ada Lovelace',
phone: '+6281234567890',
};
const sales = await request(app.getHttpServer())
.post('/employees')
.set(auth)
.send({ ...base, code: `PS_${suffix}`, position: 'sales' })
.expect(201);
const driver = await request(app.getHttpServer())
.post('/employees')
.set(auth)
.send({ ...base, code: `PD_${suffix}`, position: 'driver' })
.expect(201);
const crew = await request(app.getHttpServer())
.post('/employees')
.set(auth)
.send({ ...base, code: `PC_${suffix}`, position: 'crew' })
.expect(201);
const salesId = (sales.body as { id: string }).id;
const driverId = (driver.body as { id: string }).id;
const crewId = (crew.body as { id: string }).id;
const single = await request(app.getHttpServer())
.get(`/employees?position=sales&code=${suffix}`)
.set(auth)
.expect(200);
const singleIds = (single.body as { data: { id: string }[] }).data.map(
(row) => row.id,
);
expect(singleIds).toEqual([salesId]);
const multi = await request(app.getHttpServer())
.get(`/employees?position=sales&position=driver&code=${suffix}`)
.set(auth)
.expect(200);
const multiIds = (multi.body as { data: { id: string }[] }).data.map(
(row) => row.id,
);
expect(multiIds).toEqual(expect.arrayContaining([salesId, driverId]));
expect(multiIds).toHaveLength(2);
expect(multiIds).not.toContain(crewId);
await request(app.getHttpServer())
.get('/employees?position=pilot')
.set(auth)
.expect(400);
});
it('imports employees from CSV', async () => {
const suffix = Date.now().toString().slice(-6);
const csv =