Criteria Objekt überarbeitet
This commit is contained in:
@@ -7,7 +7,7 @@ import * as schema from '../drizzle/schema.js';
|
||||
import { PG_CONNECTION } from '../drizzle/schema.js';
|
||||
import { FileService } from '../file/file.service.js';
|
||||
import { User } from '../models/db.model.js';
|
||||
import { UserListingCriteria, emailToDirName } from '../models/main.model.js';
|
||||
import { JwtUser, UserListingCriteria, emailToDirName } from '../models/main.model.js';
|
||||
|
||||
@Injectable()
|
||||
export class UserService {
|
||||
@@ -18,30 +18,38 @@ export class UserService {
|
||||
) {}
|
||||
private getConditions(criteria: UserListingCriteria): any[] {
|
||||
const conditions = [];
|
||||
if (criteria.state) {
|
||||
//conditions.push(sql`EXISTS (SELECT 1 FROM unnest(users."areasServed") AS area WHERE area LIKE '%' || ${criteria.state} || '%')`);
|
||||
conditions.push(sql`${schema.users.areasServed} @> ${JSON.stringify([{ state: criteria.state }])}`);
|
||||
if (criteria.states?.length > 0) {
|
||||
criteria.states.forEach(state => {
|
||||
conditions.push(sql`${schema.users.areasServed} @> ${JSON.stringify([{ state: state }])}`);
|
||||
});
|
||||
}
|
||||
if (criteria.firstname || criteria.lastname) {
|
||||
conditions.push(or(ilike(schema.users.firstname, `%${criteria.lastname}%`), ilike(schema.users.lastname, `%${criteria.lastname}%`)));
|
||||
}
|
||||
return conditions;
|
||||
}
|
||||
async getUserByMail(email: string) {
|
||||
async getUserByMail(email: string, jwtuser?: JwtUser) {
|
||||
const users = (await this.conn
|
||||
.select()
|
||||
.from(schema.users)
|
||||
.where(sql`email = ${email}`)) as User[];
|
||||
const user = users[0];
|
||||
user.hasCompanyLogo = this.fileService.hasCompanyLogo(emailToDirName(user.email));
|
||||
user.hasProfile = this.fileService.hasProfile(emailToDirName(user.email));
|
||||
return user;
|
||||
if (users.length === 0) {
|
||||
const user: User = { email, firstname: jwtuser.firstname, lastname: jwtuser.lastname, customerType: 'buyer' };
|
||||
this.saveUser(user);
|
||||
return user;
|
||||
} else {
|
||||
const user = users[0];
|
||||
user.hasCompanyLogo = this.fileService.hasCompanyLogo(emailToDirName(user.email));
|
||||
user.hasProfile = this.fileService.hasProfile(emailToDirName(user.email));
|
||||
return user;
|
||||
}
|
||||
}
|
||||
async getUserById(id: string) {
|
||||
const users = (await this.conn
|
||||
.select()
|
||||
.from(schema.users)
|
||||
.where(sql`id = ${id}`)) as User[];
|
||||
|
||||
const user = users[0];
|
||||
user.hasCompanyLogo = this.fileService.hasCompanyLogo(emailToDirName(user.email));
|
||||
user.hasProfile = this.fileService.hasProfile(emailToDirName(user.email));
|
||||
|
||||
Reference in New Issue
Block a user