45 lines
1.8 KiB
TypeScript
45 lines
1.8 KiB
TypeScript
import { Get, Inject, Injectable, Param } from '@nestjs/common';
|
|
import { createClient } from 'redis';
|
|
import { Entity, Repository, Schema } from 'redis-om';
|
|
import { ListingCriteria, User } from '../models/main.model.js';
|
|
import { REDIS_CLIENT } from '../redis/redis.module.js';
|
|
import { UserEntity } from '../models/server.model.js';
|
|
import { FileService } from '../file/file.service.js';
|
|
|
|
@Injectable()
|
|
export class UserService {
|
|
userRepository:Repository;
|
|
userSchema = new Schema('user',{
|
|
id: { type: 'string' },
|
|
firstname: { type: 'string' },
|
|
lastname: { type: 'string' },
|
|
email: { type: 'string' },
|
|
phoneNumber: { type: 'string' },
|
|
companyOverview:{ type: 'string' },
|
|
companyWebsite:{ type: 'string' },
|
|
companyLocation:{ type: 'string' },
|
|
offeredServices:{ type: 'string' },
|
|
areasServed:{ type: 'string[]' },
|
|
names:{ type: 'string[]', path:'$.licensedIn.name' },
|
|
values:{ type: 'string[]', path:'$.licensedIn.value' }
|
|
}, {
|
|
dataStructure: 'JSON'
|
|
})
|
|
constructor(@Inject(REDIS_CLIENT) private readonly redis: any,private fileService:FileService){
|
|
this.userRepository = new Repository(this.userSchema, redis)
|
|
this.userRepository.createIndex();
|
|
}
|
|
async getUserById( id:string){
|
|
const user = await this.userRepository.fetch(id) as UserEntity;
|
|
user.hasCompanyLogo=this.fileService.hasCompanyLogo(id);
|
|
user.hasProfile=this.fileService.hasProfile(id);
|
|
return user;
|
|
}
|
|
async saveUser(user:any):Promise<UserEntity>{
|
|
return await this.userRepository.save(user.id,user) as UserEntity
|
|
}
|
|
async findUser(criteria:ListingCriteria){
|
|
return await this.userRepository.search().return.all();
|
|
}
|
|
|
|
} |