-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature brands relation #144
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Antes de hacer más cambios mergea main en esta rama, borra el .env
y el ormconfig.json.
El app.module
tampoco lo tendrias que tocar porque no estas agregando ningun modulo
src/brands/entities/brands.entity.ts
Outdated
}) | ||
photoId: string; | ||
@OneToOne(() => PhotosEntity) @JoinColumn() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
la relacion está mal hecha. estábamos usando relaciones polimórifcas y no one to one.
igualmente en una relación one to one tendrias que cambiar @JoinColumn()
por @JoinColumn({ name: 'photo_id' })
photoId: Number
por photo: PhotosEntity
@IsInt() | ||
@ApiProperty({ | ||
example: 123, | ||
description: 'The id of the brand', | ||
type: Number, | ||
}) | ||
id: number; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no se le tiene que pasar un id cuando creas
@@ -38,19 +37,19 @@ describe('brandsController', () => { | |||
}); | |||
|
|||
it('should create a brand', () => { | |||
expect(controller.create({ name: 'Mario', photoId: 'ph id' })).toEqual({ | |||
expect(controller.create({ id:1, name: 'Mario', photoId: 123 })).toEqual({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no pasarle id cuando creas
}); | ||
}); | ||
|
||
it('should update a brand', () => { | ||
const dto: createBrandDTO = { name: 'Mario', photoId: 'ph id' }; | ||
const dto: createBrandDTO = { id: 1, name: 'Mario', photoId: 123 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cuando haces un update el id se lo pasas en la ruta, no en el dto
findAll(): Promise<Brand[]> { | ||
return this.brandRepo.find(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
borrar este método porque no se usa
@@ -15,20 +15,20 @@ export class BrandsService { | |||
private brandRepo: Repository<Brand>, | |||
) {} | |||
|
|||
findOne(id: number) { | |||
findOne(id: number): Promise<Brand> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
falta tirar un 404 cuando no encuentra el brand
const newBrand = this.brandRepo.create(body); | ||
return this.brandRepo.save(newBrand); | ||
} | ||
|
||
async update(id: number, body: any) { | ||
async update(id: number, body: any): Promise<Brand> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
falta tirar un 404 cuando no encuenta el id
lo mismo para delete
ademas aca tiene que recibir el dto, no un any
return this.brandRepo.find(); | ||
} | ||
|
||
create(body: any) { | ||
create(body: any): Promise<Brand[]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiene que recibir el dto, no un any
RESUMEN
#42
photoId está relacionado con la tabla photo
brands test fixed