Skip to content

Commit d7a7ae8

Browse files
committed
fix: Some template bugs with other secjs packages
1 parent 8b95a19 commit d7a7ae8

File tree

11 files changed

+48
-22
lines changed

11 files changed

+48
-22
lines changed

app/templates/nestjsMongoose/E2E/__name__/update.spec.ts.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('\n[E2E] <%= namePascal %> 🛠', () => {
1111

1212
const status = 200
1313
const method = 'PUT'
14-
const path = `/<%= namePluralCamel %>/${<%= nameCamel %>.id}?apiKey=${apiKey}`
14+
const path = `/<%= namePluralCamel %>/${<%= nameCamel %>.id}`
1515

1616
const payload = {
1717
name: 'test',
@@ -31,7 +31,7 @@ describe('\n[E2E] <%= namePascal %> 🛠', () => {
3131
it('should throw a not found error when can not find <%= nameCamel %>', async () => {
3232
const status = 404
3333
const method = 'PUT'
34-
const path = `/<%= namePluralCamel %>/507f1f77bcf86cd799439011?apiKey=${apiKey}`
34+
const path = `/<%= namePluralCamel %>/507f1f77bcf86cd799439011`
3535

3636
const { body } = await request(app.server.getHttpServer())
3737
.put(path)

app/templates/nestjsMongoose/__name__.ts.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
import * as mongoose from 'mongoose'
2-
import { Schema, SchemaFactory } from '@nestjs/mongoose'
2+
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
33

44
@Schema({ timestamps: true })
55
export class <%= namePascal %> {
6-
// <%= namePascal %> props goes in here
6+
@Prop({ type: String, default: 'pendent' })
7+
status: 'pendent' | 'canceled' | 'active' | 'deleted'
8+
9+
@Prop({ type: Date, default: null })
10+
deletedAt?: Date
11+
12+
createdAt: Date
13+
14+
updatedAt: Date
715
}
816

917
export type <%= namePascal %>Document = <%= namePascal %> & mongoose.Document

app/templates/nestjsMongoose/__name__Repository.ts.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { Model } from 'mongoose'
22
import { Injectable } from '@nestjs/common'
33
import { InjectModel } from '@nestjs/mongoose'
44
import { <%= namePascal %>, <%= namePascal %>Document } from 'app/Schemas/<%= namePascal %>'
5-
import { MongooseRepository } from '@secjs/core/base/Repositories/MongooseRepository'
5+
import { MongooseRepository } from '@secjs/base/Repositories/MongooseRepository'
66

77
@Injectable()
88
export class <%= namePascal %>Repository extends MongooseRepository<<%= namePascal %>Document> {
9-
protected wheres: []
10-
protected relations: []
9+
wheres = []
10+
relations = []
1111

1212
@InjectModel(<%= namePascal %>.name)
13-
protected Model = Model<<%= namePascal %>Document>
13+
model: Model<<%= namePascal %>Document>
1414
}

app/templates/nestjsMongoose/__name__Resource.ts.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@ export class <%= namePascal %>Resource {
2121
deletedAt: model.deletedAt,
2222
}
2323

24+
// For OneToMany relation
2425
// if (model.relations && isArrayOfObjects(model.relations)) {
2526
// json.relations = new YourRelationResource().toArray(
2627
// model.relations,
2728
// )
2829
// }
2930

31+
// For ManyToOne relation
32+
// if (document.project?.toJSON()?._id) {
33+
// json.relation = new YourRelationResource().toJson(document.relation)
34+
// }
35+
3036
return json
3137
}
3238

app/templates/nestjsPrismaOrm/E2E/__name__/update.spec.ts.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('\n[E2E] <%= namePascal %> 🛠', () => {
1111

1212
const status = 200
1313
const method = 'PUT'
14-
const path = `/<%= namePluralCamel %>/${<%= nameCamel %>.id}?apiKey=${apiKey}`
14+
const path = `/<%= namePluralCamel %>/${<%= nameCamel %>.id}`
1515

1616
const payload = {
1717
name: 'test',
@@ -31,7 +31,7 @@ describe('\n[E2E] <%= namePascal %> 🛠', () => {
3131
it('should throw a not found error when can not find <%= nameCamel %>', async () => {
3232
const status = 404
3333
const method = 'PUT'
34-
const path = `/<%= namePluralCamel %>/507f1f77bcf86cd799439011?apiKey=${apiKey}`
34+
const path = `/<%= namePluralCamel %>/507f1f77bcf86cd799439011`
3535

3636
const { body } = await request(app.server.getHttpServer())
3737
.put(path)

app/templates/nestjsPrismaOrm/__name__Repository.ts.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import { PrismaRepository } from '@secjs/base/repositories/PrismaRepository'
55

66
@Injectable()
77
export class <%= namePascal %>Repository extends PrismaRepository<<%= namePascal %>> {
8-
protected wheres: []
9-
protected relations: []
8+
wheres = []
9+
relations = []
1010

11-
protected Model: any
11+
model: any
1212

1313
constructor(private prisma: PrismaService) {
1414
super()
1515

16-
this.Model = this.prisma.<%= nameCamel %>
16+
this.model = this.prisma.<%= nameCamel %>
1717
}
1818
}

app/templates/nestjsPrismaOrm/__name__Resource.ts.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,18 @@ export class <%= namePascal %>Resource {
2020
deletedAt: model.deletedAt,
2121
}
2222

23+
// For OneToMany relation
2324
// if (model.relations && isArrayOfObjects(model.relations)) {
2425
// json.relations = new YourRelationResource().toArray(
2526
// model.relations,
2627
// )
2728
// }
2829

30+
// For ManyToOne relation
31+
// if (model.relation?.id) {
32+
// json.relation = new YourRelationResource().toJson(model.relation)
33+
// }
34+
2935
return json
3036
}
3137

app/templates/nestjsTypeOrm/E2E/__name__/update.spec.ts.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('\n[E2E] <%= namePascal %> 🛠', () => {
1111

1212
const status = 200
1313
const method = 'PUT'
14-
const path = `/<%= namePluralCamel %>/${<%= nameCamel %>.id}?apiKey=${apiKey}`
14+
const path = `/<%= namePluralCamel %>/${<%= nameCamel %>.id}`
1515

1616
const payload = {
1717
name: 'test',
@@ -31,7 +31,7 @@ describe('\n[E2E] <%= namePascal %> 🛠', () => {
3131
it('should throw a not found error when can not find <%= nameCamel %>', async () => {
3232
const status = 404
3333
const method = 'PUT'
34-
const path = `/<%= namePluralCamel %>/507f1f77bcf86cd799439011?apiKey=${apiKey}`
34+
const path = `/<%= namePluralCamel %>/507f1f77bcf86cd799439011`
3535

3636
const { body } = await request(app.server.getHttpServer())
3737
.put(path)
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import { EntityRepository } from 'typeorm'
12
import { <%= namePascal %> } from 'app/Models/<%= namePascal %>'
2-
import { Injectable } from '@nestjs/common'
33
import { TypeOrmRepository } from '@secjs/base/repositories/TypeOrmRepository'
44

5-
@Injectable()
5+
@EntityRepository(<%= namePascal %>)
66
export class <%= namePascal %>Repository extends TypeOrmRepository<<%= namePascal %>> {
7-
protected wheres: []
8-
protected relations: []
7+
wheres = []
8+
relations = []
99

10-
protected Model = <%= namePascal %>
10+
model = <%= namePascal %>.name
1111
}

app/templates/nestjsTypeOrm/__name__Resource.ts.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,18 @@ export class <%= namePascal %>Resource {
2020
deletedAt: model.deletedAt,
2121
}
2222

23+
// For OneToMany relation
2324
// if (model.relations && isArrayOfObjects(model.relations)) {
2425
// json.relations = new YourRelationResource().toArray(
2526
// model.relations,
2627
// )
2728
// }
2829

30+
// For ManyToOne relation
31+
// if (model.relation?.id) {
32+
// json.relation = new YourRelationResource().toJson(model.relation)
33+
// }
34+
2935
return json
3036
}
3137

0 commit comments

Comments
 (0)