44} from 'app/Contracts/Dtos/<%= namePascal %>Dto'
55
66import { Options } from 'app/Decorators/Services/Options'
7+ import { <%= namePascal %>Resource } from 'app/Resources/<%= namePascal %>Resource'
78import { <%= namePascal %>Repository } from 'app/Repositories/<%= namePascal %>Repository'
89import { Inject, Injectable, NotFoundException } from '@nestjs/common'
910import { ApiRequestContract, PaginationContract } from '@secjs/contracts'
@@ -15,7 +16,13 @@ export class <%= namePascal %>Service {
1516
1617 @Options()
1718 async findAll(paginate: PaginationContract, options?: ApiRequestContract) {
18- return this.<%= nameCamel %>Repository.getAll(paginate, options)
19+ const { data, meta, links }: any = await this.<%= nameCamel %>Repository.getAll(paginate, options)
20+
21+ return {
22+ meta,
23+ links,
24+ data: new <%= namePascal %>Resource().toArray(data),
25+ }
1926 }
2027
2128 @Options()
@@ -26,22 +33,24 @@ export class <%= namePascal %>Service {
2633 throw new NotFoundException('NOT_FOUND_<%= nameUp %>')
2734 }
2835
29- return <%= nameCamel %>
36+ return new <%= namePascal %>Resource().toJson(<%= nameCamel %>)
3037 }
3138
3239 async createOne(dto: Create<%= namePascal %>Dto) {
33- return this.<%= nameCamel %>Repository.storeOne(dto)
40+ const <%= nameCamel %> = await this.<%= nameCamel %>Repository.storeOne(dto)
41+
42+ return new <%= namePascal %>Resource().toJson(<%= nameCamel %>)
3443 }
3544
3645 async updateOne(id: string, dto: Update<%= namePascal %>Dto) {
37- const <%= nameCamel %> = await this.findOne(id)
46+ const <%= nameCamel %> = await this.<%= nameCamel %>Repository.updateOne(await this. findOne(id), dto )
3847
39- return this. <%= nameCamel %>Repository.updateOne (<%= nameCamel %>, dto )
48+ return new <%= namePascal %>Resource().toJson (<%= nameCamel %>)
4049 }
4150
4251 async deleteOne(id: string) {
43- const <%= nameCamel %> = await this.findOne(id)
52+ const <%= nameCamel %> = await this.<%= nameCamel %>Repository.deleteOne(await this. findOne(id) )
4453
45- return this. <%= nameCamel %>Repository.deleteOne (<%= nameCamel %>)
54+ return new <%= namePascal %>Resource().toJson (<%= nameCamel %>)
4655 }
4756}
0 commit comments