Add user and employee management enhancements with database schema updates

- Introduced new columns `status`, `created_by`, and `updated_by` in the `users` table to track user status and ownership.
- Updated the `employees` table to include a foreign key reference to the `users` table via `user_id`.
- Created migration script `0012_users_primary.sql` to apply these changes to the database schema.
- Enhanced the `EmployeesService` and `EmployeesRepository` to support user assignments and related data retrieval.
- Updated DTOs and service methods to reflect the new user and employee relationships.
- Added unit tests to validate the new functionality and ensure data integrity.
- Modified existing controllers to accommodate the new fields and relationships in user and employee management.
This commit is contained in:
shancheas
2026-08-26 15:29:18 +07:00
parent f635ebeda0
commit 8a61c94078
50 changed files with 2175 additions and 401 deletions
+25 -14
View File
@@ -4,9 +4,12 @@ import request from 'supertest';
import { App } from 'supertest/types';
import { AppModule } from '../src/app.module';
import { configureApp } from '../src/common/configure-app';
import { DRIZZLE, type DrizzleDB } from '../src/database/database.module';
import { registerAndActivate } from './helpers/activate-user';
describe('Auth (e2e)', () => {
let app: INestApplication<App>;
let db: DrizzleDB;
const username = `user_${Date.now()}`;
const password = 'password123';
@@ -22,6 +25,7 @@ describe('Auth (e2e)', () => {
SWAGGER_ENABLED: 'false',
});
await app.init();
db = app.get(DRIZZLE);
});
afterAll(async () => {
@@ -39,30 +43,37 @@ describe('Auth (e2e)', () => {
await request(app.getHttpServer()).get('/auth/me').expect(401);
});
it('register → me → refresh → revoke → me 401', async () => {
it('register creates a draft user without tokens; login works after activate', async () => {
const register = await request(app.getHttpServer())
.post('/auth/register')
.send({ username, password })
.expect(201);
const { accessToken, refreshToken } = register.body as {
accessToken: string;
refreshToken: string;
};
expect(accessToken).toBeDefined();
expect(refreshToken).toHaveLength(64);
expect(Object.keys(register.body).sort()).toEqual([
'accessToken',
'refreshToken',
]);
expect(register.body).toMatchObject({
username: username.toLowerCase(),
status: 'draft',
});
expect(register.body).not.toHaveProperty('accessToken');
await request(app.getHttpServer())
.post('/auth/login')
.send({ username, password })
.expect(401);
const activated = await registerAndActivate(
app,
db,
`${username}_active`,
password,
);
const me = await request(app.getHttpServer())
.get('/auth/me')
.set('Authorization', `Bearer ${accessToken}`)
.set('Authorization', `Bearer ${activated.accessToken}`)
.expect(200);
expect(me.body).toMatchObject({
username: username.toLowerCase(),
username: `${username}_active`.toLowerCase(),
isSuperadmin: false,
privilege: null,
permissions: {},
@@ -70,7 +81,7 @@ describe('Auth (e2e)', () => {
const refreshed = await request(app.getHttpServer())
.post('/auth/refresh')
.send({ refreshToken })
.send({ refreshToken: activated.refreshToken })
.expect(200);
const { accessToken: nextAccess, refreshToken: nextRefresh } =