@vori/nest-schematics
Advanced tools
Comparing version 1.0.6 to 1.1.0
@@ -81,3 +81,3 @@ import { INestApplication } from '@nestjs/common'; | ||
// TODO Add fields | ||
const body: Create<%= singular(classify(name)) %>Dto = {}; | ||
const body: new Create<%= singular(classify(name)) %>Dto({}); | ||
@@ -90,7 +90,6 @@ const response = await request(app.getHttpServer()) | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
const <%= singular(camelize(name)) %> = await <%= lowercased(name) %>Service.findOne( | ||
user!, | ||
response.body.id | ||
); | ||
const <%= singular(camelize(name)) %> = await <%= lowercased(name) %>Service.findOne({ | ||
bannerID: banner.id, | ||
id: response.body.id, | ||
}); | ||
// TODO Assert values stored in database | ||
@@ -97,0 +96,0 @@ |
import { Injectable, Logger } from '@nestjs/common'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
import { BannerMember } from '@vori/types/User';<% if (crud && type !== 'graphql-code-first' && type !== 'graphql-schema-first') { %> | ||
import { Repository } from 'typeorm';<% if (crud && type !== 'graphql-code-first' && type !== 'graphql-schema-first') { %> | ||
import { Create<%= singular(classify(name)) %>Dto, Update<%= singular(classify(name)) %>Dto } from './dto/<%= singular(name) %>.dto';<% } else if (crud) { %> | ||
@@ -19,3 +18,3 @@ import { Create<%= singular(classify(name)) %>Input } from './dto/create-<%= singular(name) %>.input'; | ||
<% if (crud) { %> | ||
public async create(<% if (type !== 'graphql-code-first' && type !== 'graphql-schema-first') { %>user: BannerMember, dto: Create<%= singular(classify(name)) %>Dto<% } else { %>create<%= singular(classify(name)) %>Input: Create<%= singular(classify(name)) %>Input<% } %>): Promise<<%= classify(singular(name)) %>> {<% if (crud && type == 'rest') { %> | ||
public async create(<% if (type !== 'graphql-code-first' && type !== 'graphql-schema-first') { %>{bannerID, dto}: {bannerID: string, dto: Create<%= singular(classify(name)) %>Dto}<% } else { %>create<%= singular(classify(name)) %>Input: Create<%= singular(classify(name)) %>Input<% } %>): Promise<<%= classify(singular(name)) %>> {<% if (crud && type == 'rest') { %> | ||
const <%= singular(camelize(name)) %> = this.dtoToModel(dto); | ||
@@ -25,3 +24,3 @@ | ||
// NOTE: Set this only on creation. Banner IDs are not allowed to change. | ||
<%= singular(camelize(name)) %>.bannerID = user.bannerID; | ||
<%= singular(camelize(name)) %>.bannerID = bannerID; | ||
@@ -32,7 +31,7 @@ return this.<%= camelize(name) %>Repository.save(<%= singular(camelize(name)) %>);<% } else { %> | ||
public async findAll(user: BannerMember): Promise<<%= classify(singular(name)) %>[]> {<% if (crud && type == 'rest') { %> | ||
public async findAll({bannerID}: {bannerID: string}): Promise<<%= classify(singular(name)) %>[]> {<% if (crud && type == 'rest') { %> | ||
// TODO Adjust the query if the data is not associated with a banner | ||
return this.<%= camelize(name) %>Repository.find({ | ||
comment: `controller='<%= classify(name) %>Service',action='findAll'`, | ||
where: { bannerID: user.bannerID }, | ||
where: { bannerID }, | ||
order: { | ||
@@ -45,7 +44,7 @@ createdAt: 'DESC', | ||
public async findOne(user: BannerMember, id: string): Promise<<%= classify(singular(name)) %>> {<% if (crud && type == 'rest') { %> | ||
public async findOne({bannerID, id}: {bannerID: string; id: string}): Promise<<%= classify(singular(name)) %>> {<% if (crud && type == 'rest') { %> | ||
// TODO Adjust the query if the data is not associated with a banner | ||
return this.<%= camelize(name) %>Repository.findOneOrFail({ | ||
comment: `controller='<%= classify(name) %>Service',action='findOne'`, | ||
where: { id: id.toString(), bannerID: user.bannerID }, | ||
where: { id: id.toString(), bannerID }, | ||
});<% } else { %> | ||
@@ -55,4 +54,4 @@ return `This action returns a #${id} <%= lowercased(singular(classify(name))) %>`;<% } %> | ||
public async update(user: BannerMember, id: string, <% if (type !== 'graphql-code-first' && type !== 'graphql-schema-first') { %>dto: Update<%= singular(classify(name)) %>Dto<% } else { %>update<%= singular(classify(name)) %>Input: Update<%= singular(classify(name)) %>Input<% } %>): Promise<<%= classify(singular(name)) %>> {<% if (crud && type == 'rest') { %> | ||
const <%= singular(camelize(name)) %> = await this.findOne(user, id); | ||
public async update(<% if (type !== 'graphql-code-first' && type !== 'graphql-schema-first') { %>{bannerID, id, dto}: {bannerID: string; id: string; dto: Update<%= singular(classify(name)) %>Dto}<% } else { %>update<%= singular(classify(name)) %>Input: Update<%= singular(classify(name)) %>Input<% } %>): Promise<<%= classify(singular(name)) %>> {<% if (crud && type == 'rest') { %> | ||
const <%= singular(camelize(name)) %> = await this.findOne({bannerID, id}); | ||
const updates = this.dtoToModel(dto); | ||
@@ -65,4 +64,4 @@ return this.<%= camelize(name) %>Repository.save( | ||
public async remove(user: BannerMember, id: string): Promise<void> {<% if (crud && type == 'rest') { %> | ||
const <%= singular(camelize(name)) %> = await this.findOne(user, id); | ||
public async remove({bannerID, id}: {bannerID: string; id: string}): Promise<void> {<% if (crud && type == 'rest') { %> | ||
const <%= singular(camelize(name)) %> = await this.findOne({bannerID, id}); | ||
await this.<%= camelize(name) %>Repository.remove(<%= singular(camelize(name)) %>);<% } else { %> | ||
@@ -69,0 +68,0 @@ return `This action removes a #${id} <%= lowercased(singular(classify(name))) %>`;<% } %> |
@@ -11,4 +11,8 @@ <% if (isSwaggerInstalled) { %>import { PartialType } from '@nestjs/swagger';<% } else { %>import { PartialType } from '@nestjs/mapped-types';<% } %> | ||
export class Create<%= singular(classify(name)) %>Dto {} | ||
export class Create<%= singular(classify(name)) %>Dto { | ||
public constructor(data?: Partial<Create<%= singular(classify(name)) %>Dto>) { | ||
Object.assign(this, data); | ||
} | ||
} | ||
export class Update<%= singular(classify(name)) %>Dto extends PartialType(Create<%= singular(classify(name)) %>Dto) {} |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "1.0.6", | ||
"version": "1.1.0", | ||
"description": "Nest - modern, fast, powerful node.js web framework (@schematics)", | ||
@@ -10,0 +10,0 @@ "main": "dist/index.js", |
203869
5031