First commit
This commit is contained in:
43
api/src/experience/experience.service.ts
Normal file
43
api/src/experience/experience.service.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ExperienceEntity } from './experience.entity';
|
||||
import { ExperienceDto } from './experience.dto';
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { DeleteResult, Repository } from "typeorm";
|
||||
|
||||
@Injectable()
|
||||
export class ExperienceService {
|
||||
constructor(
|
||||
@InjectRepository(ExperienceEntity) private readonly experienceRepository: Repository<ExperienceEntity>
|
||||
) {}
|
||||
|
||||
async find(id: string): Promise<ExperienceEntity> {
|
||||
return await this.experienceRepository.findOne({
|
||||
where: { id: id },
|
||||
relations: ['profile', 'status']
|
||||
})
|
||||
}
|
||||
|
||||
async findAll(): Promise<ExperienceEntity[]> {
|
||||
return await this.experienceRepository.find({
|
||||
relations: ['profile', 'status']
|
||||
});
|
||||
}
|
||||
|
||||
async create(experience: ExperienceDto): Promise<ExperienceDto> {
|
||||
return await this.experienceRepository.save(experience);
|
||||
}
|
||||
|
||||
async update(
|
||||
id: string,
|
||||
experienceDto: ExperienceDto
|
||||
): Promise<ExperienceDto> {
|
||||
const experienceEntity: ExperienceEntity = await this.experienceRepository.findOneBy({ id })
|
||||
const experienceEntityUpdated = Object.assign(experienceEntity, experienceDto)
|
||||
|
||||
return await this.experienceRepository.save(experienceEntityUpdated)
|
||||
}
|
||||
|
||||
async delete(id: string): Promise<DeleteResult> {
|
||||
return await this.experienceRepository.delete({ id })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user