fix issues
This commit is contained in:
@@ -6,13 +6,13 @@ export class AdminUserOrmEntity {
|
||||
id!: string;
|
||||
|
||||
@Index()
|
||||
@Column({ type: 'text', unique: true })
|
||||
@Column({ type: 'text' })
|
||||
email!: string;
|
||||
|
||||
@Column({ type: 'text' })
|
||||
displayName!: string;
|
||||
|
||||
@Column({ type: 'jsonb' })
|
||||
@Column({ type: 'simple-json' })
|
||||
roles!: string[];
|
||||
|
||||
@Column({ type: 'text' })
|
||||
@@ -21,12 +21,12 @@ export class AdminUserOrmEntity {
|
||||
@Column({ type: 'text', nullable: true })
|
||||
primaryDriverId?: string;
|
||||
|
||||
@Column({ type: 'timestamptz', nullable: true })
|
||||
@Column({ type: 'datetime', nullable: true })
|
||||
lastLoginAt?: Date;
|
||||
|
||||
@CreateDateColumn({ type: 'timestamptz' })
|
||||
@CreateDateColumn({ type: 'datetime' })
|
||||
createdAt!: Date;
|
||||
|
||||
@UpdateDateColumn({ type: 'timestamptz' })
|
||||
@UpdateDateColumn({ type: 'datetime' })
|
||||
updatedAt!: Date;
|
||||
}
|
||||
@@ -26,7 +26,9 @@ describe('TypeOrmAdminUserRepository', () => {
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await dataSource.destroy();
|
||||
if (dataSource.isInitialized) {
|
||||
await dataSource.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
|
||||
@@ -54,30 +54,31 @@ export class TypeOrmAdminUserRepository implements IAdminUserRepository {
|
||||
const sortBy = query?.sort?.field ?? 'createdAt';
|
||||
const sortOrder = query?.sort?.direction ?? 'desc';
|
||||
|
||||
const where: Record<string, unknown> = {};
|
||||
const queryBuilder = this.repository.createQueryBuilder('adminUser');
|
||||
|
||||
if (query?.filter?.role) {
|
||||
where.roles = { $contains: [query.filter.role.value] };
|
||||
// SQLite doesn't support ANY, use LIKE for JSON array search
|
||||
queryBuilder.andWhere('adminUser.roles LIKE :rolePattern', {
|
||||
rolePattern: `%${query.filter.role.value}%`
|
||||
});
|
||||
}
|
||||
|
||||
if (query?.filter?.status) {
|
||||
where.status = query.filter.status.value;
|
||||
queryBuilder.andWhere('adminUser.status = :status', { status: query.filter.status.value });
|
||||
}
|
||||
|
||||
if (query?.filter?.search) {
|
||||
where.email = this.repository.manager.connection
|
||||
.createQueryBuilder()
|
||||
.where('email ILIKE :search', { search: `%${query.filter.search}%` })
|
||||
.orWhere('displayName ILIKE :search', { search: `%${query.filter.search}%` })
|
||||
.getQuery();
|
||||
const searchParam = `%${query.filter.search}%`;
|
||||
queryBuilder.andWhere(
|
||||
'(adminUser.email LIKE :search OR adminUser.displayName LIKE :search)',
|
||||
{ search: searchParam }
|
||||
);
|
||||
}
|
||||
|
||||
const [entities, total] = await this.repository.findAndCount({
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
order: { [sortBy]: sortOrder },
|
||||
});
|
||||
queryBuilder.skip(skip).take(limit);
|
||||
queryBuilder.orderBy(`adminUser.${sortBy}`, sortOrder.toUpperCase() as 'ASC' | 'DESC');
|
||||
|
||||
const [entities, total] = await queryBuilder.getManyAndCount();
|
||||
|
||||
const users = entities.map(entity => this.mapper.toDomain(entity));
|
||||
|
||||
@@ -91,25 +92,28 @@ export class TypeOrmAdminUserRepository implements IAdminUserRepository {
|
||||
}
|
||||
|
||||
async count(filter?: UserFilter): Promise<number> {
|
||||
const where: Record<string, unknown> = {};
|
||||
const queryBuilder = this.repository.createQueryBuilder('adminUser');
|
||||
|
||||
if (filter?.role) {
|
||||
where.roles = { $contains: [filter.role.value] };
|
||||
// SQLite doesn't support ANY, use LIKE for JSON array search
|
||||
queryBuilder.andWhere('adminUser.roles LIKE :rolePattern', {
|
||||
rolePattern: `%${filter.role.value}%`
|
||||
});
|
||||
}
|
||||
|
||||
if (filter?.status) {
|
||||
where.status = filter.status.value;
|
||||
queryBuilder.andWhere('adminUser.status = :status', { status: filter.status.value });
|
||||
}
|
||||
|
||||
if (filter?.search) {
|
||||
where.email = this.repository.manager.connection
|
||||
.createQueryBuilder()
|
||||
.where('email ILIKE :search', { search: `%${filter.search}%` })
|
||||
.orWhere('displayName ILIKE :search', { search: `%${filter.search}%` })
|
||||
.getQuery();
|
||||
const searchParam = `%${filter.search}%`;
|
||||
queryBuilder.andWhere(
|
||||
'(adminUser.email LIKE :search OR adminUser.displayName LIKE :search)',
|
||||
{ search: searchParam }
|
||||
);
|
||||
}
|
||||
|
||||
return await this.repository.count({ where });
|
||||
return await queryBuilder.getCount();
|
||||
}
|
||||
|
||||
async create(user: AdminUser): Promise<AdminUser> {
|
||||
|
||||
Reference in New Issue
Block a user