Skip to content

Commit

Permalink
fix: Some template bugs with other secjs packages
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Oct 9, 2021
1 parent 8b95a19 commit d7a7ae8
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 22 deletions.
4 changes: 2 additions & 2 deletions app/templates/nestjsMongoose/E2E/__name__/update.spec.ts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('\n[E2E] <%= namePascal %> 🛠', () => {

const status = 200
const method = 'PUT'
const path = `/<%= namePluralCamel %>/${<%= nameCamel %>.id}?apiKey=${apiKey}`
const path = `/<%= namePluralCamel %>/${<%= nameCamel %>.id}`

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

const { body } = await request(app.server.getHttpServer())
.put(path)
Expand Down
12 changes: 10 additions & 2 deletions app/templates/nestjsMongoose/__name__.ts.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import * as mongoose from 'mongoose'
import { Schema, SchemaFactory } from '@nestjs/mongoose'
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'

@Schema({ timestamps: true })
export class <%= namePascal %> {
// <%= namePascal %> props goes in here
@Prop({ type: String, default: 'pendent' })
status: 'pendent' | 'canceled' | 'active' | 'deleted'

@Prop({ type: Date, default: null })
deletedAt?: Date

createdAt: Date

updatedAt: Date
}

export type <%= namePascal %>Document = <%= namePascal %> & mongoose.Document
Expand Down
8 changes: 4 additions & 4 deletions app/templates/nestjsMongoose/__name__Repository.ts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { Model } from 'mongoose'
import { Injectable } from '@nestjs/common'
import { InjectModel } from '@nestjs/mongoose'
import { <%= namePascal %>, <%= namePascal %>Document } from 'app/Schemas/<%= namePascal %>'
import { MongooseRepository } from '@secjs/core/base/Repositories/MongooseRepository'
import { MongooseRepository } from '@secjs/base/Repositories/MongooseRepository'

@Injectable()
export class <%= namePascal %>Repository extends MongooseRepository<<%= namePascal %>Document> {
protected wheres: []
protected relations: []
wheres = []
relations = []

@InjectModel(<%= namePascal %>.name)
protected Model = Model<<%= namePascal %>Document>
model: Model<<%= namePascal %>Document>
}
6 changes: 6 additions & 0 deletions app/templates/nestjsMongoose/__name__Resource.ts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ export class <%= namePascal %>Resource {
deletedAt: model.deletedAt,
}

// For OneToMany relation
// if (model.relations && isArrayOfObjects(model.relations)) {
// json.relations = new YourRelationResource().toArray(
// model.relations,
// )
// }

// For ManyToOne relation
// if (document.project?.toJSON()?._id) {
// json.relation = new YourRelationResource().toJson(document.relation)
// }

return json
}

Expand Down
4 changes: 2 additions & 2 deletions app/templates/nestjsPrismaOrm/E2E/__name__/update.spec.ts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('\n[E2E] <%= namePascal %> 🛠', () => {

const status = 200
const method = 'PUT'
const path = `/<%= namePluralCamel %>/${<%= nameCamel %>.id}?apiKey=${apiKey}`
const path = `/<%= namePluralCamel %>/${<%= nameCamel %>.id}`

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

const { body } = await request(app.server.getHttpServer())
.put(path)
Expand Down
8 changes: 4 additions & 4 deletions app/templates/nestjsPrismaOrm/__name__Repository.ts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { PrismaRepository } from '@secjs/base/repositories/PrismaRepository'

@Injectable()
export class <%= namePascal %>Repository extends PrismaRepository<<%= namePascal %>> {
protected wheres: []
protected relations: []
wheres = []
relations = []

protected Model: any
model: any

constructor(private prisma: PrismaService) {
super()

this.Model = this.prisma.<%= nameCamel %>
this.model = this.prisma.<%= nameCamel %>
}
}
6 changes: 6 additions & 0 deletions app/templates/nestjsPrismaOrm/__name__Resource.ts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ export class <%= namePascal %>Resource {
deletedAt: model.deletedAt,
}

// For OneToMany relation
// if (model.relations && isArrayOfObjects(model.relations)) {
// json.relations = new YourRelationResource().toArray(
// model.relations,
// )
// }

// For ManyToOne relation
// if (model.relation?.id) {
// json.relation = new YourRelationResource().toJson(model.relation)
// }

return json
}

Expand Down
4 changes: 2 additions & 2 deletions app/templates/nestjsTypeOrm/E2E/__name__/update.spec.ts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('\n[E2E] <%= namePascal %> 🛠', () => {

const status = 200
const method = 'PUT'
const path = `/<%= namePluralCamel %>/${<%= nameCamel %>.id}?apiKey=${apiKey}`
const path = `/<%= namePluralCamel %>/${<%= nameCamel %>.id}`

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

const { body } = await request(app.server.getHttpServer())
.put(path)
Expand Down
10 changes: 5 additions & 5 deletions app/templates/nestjsTypeOrm/__name__Repository.ts.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { EntityRepository } from 'typeorm'
import { <%= namePascal %> } from 'app/Models/<%= namePascal %>'
import { Injectable } from '@nestjs/common'
import { TypeOrmRepository } from '@secjs/base/repositories/TypeOrmRepository'

@Injectable()
@EntityRepository(<%= namePascal %>)
export class <%= namePascal %>Repository extends TypeOrmRepository<<%= namePascal %>> {
protected wheres: []
protected relations: []
wheres = []
relations = []

protected Model = <%= namePascal %>
model = <%= namePascal %>.name
}
6 changes: 6 additions & 0 deletions app/templates/nestjsTypeOrm/__name__Resource.ts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ export class <%= namePascal %>Resource {
deletedAt: model.deletedAt,
}

// For OneToMany relation
// if (model.relations && isArrayOfObjects(model.relations)) {
// json.relations = new YourRelationResource().toArray(
// model.relations,
// )
// }

// For ManyToOne relation
// if (model.relation?.id) {
// json.relation = new YourRelationResource().toJson(model.relation)
// }

return json
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "generator-secjs",
"version": "1.2.5",
"version": "1.2.6",
"description": "🧬 Generator for any NodeJS Project or Framework",
"main": "app/index.js",
"scripts": {
Expand Down

0 comments on commit d7a7ae8

Please sign in to comment.