- Updated pagination-response and read-write-controllers documentation to include `orderBy` and `orderType` parameters for sorting results. - Introduced new `order-clause` module to handle ordering logic, including validation for order types and columns. - Enhanced `PaginationQueryDto` to support ordering fields in API requests. - Updated various repository and service classes to implement ordering in database queries. - Added unit tests for new ordering functionality and ensured existing tests cover the updated behavior. - Refactored related DTOs to include user and code relations for better data representation in responses.
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { INestApplication } from '@nestjs/common';
|
|
import { eq } from 'drizzle-orm';
|
|
import request from 'supertest';
|
|
import { users } from '../../src/database/schema';
|
|
import type { DrizzleDB } from '../../src/database/database.module';
|
|
|
|
export async function registerAndActivate(
|
|
app: INestApplication,
|
|
db: DrizzleDB,
|
|
username: string,
|
|
password: string,
|
|
): Promise<{ accessToken: string; refreshToken: string; userId: string }> {
|
|
const register = await request(app.getHttpServer())
|
|
.post('/auth/register')
|
|
.send({ username, password });
|
|
if (register.status !== 201) {
|
|
throw new Error(
|
|
`register failed ${register.status} ${JSON.stringify(register.body)}`,
|
|
);
|
|
}
|
|
const userId = (register.body as { id: string }).id;
|
|
await db.update(users).set({ status: 'active' }).where(eq(users.id, userId));
|
|
const login = await request(app.getHttpServer())
|
|
.post('/auth/login')
|
|
.send({ username, password });
|
|
if (login.status !== 200) {
|
|
throw new Error(
|
|
`login failed ${login.status} ${JSON.stringify(login.body)}`,
|
|
);
|
|
}
|
|
const tokens = login.body as { accessToken: string; refreshToken: string };
|
|
return {
|
|
userId,
|
|
accessToken: tokens.accessToken,
|
|
refreshToken: tokens.refreshToken,
|
|
};
|
|
}
|