fix: fixed category updating

This commit is contained in:
Sergey Yarkov 2022-01-22 19:46:58 +03:00
parent bac861a09d
commit 6248134614
4 changed files with 5 additions and 10 deletions

View File

@ -14,7 +14,7 @@ export default class Category extends BaseModel {
public title: string; public title: string;
@column() @column()
public description: string; public description: string | null;
@column({ serializeAs: null }) @column({ serializeAs: null })
public color_id: number | null; public color_id: number | null;

View File

@ -70,6 +70,7 @@ export default class CategoryRepository {
} }
/** /**
* Update category by id
* *
* @param id Category id * @param id Category id
* @param data * @param data
@ -79,13 +80,7 @@ export default class CategoryRepository {
const category = await this.Category.query().where('id', id).first(); const category = await this.Category.query().where('id', id).first();
if (category) { if (category) {
await category await category.merge(data).save();
.merge({
title: data.title,
description: data.description,
})
.save();
return category; return category;
} }

View File

@ -144,7 +144,7 @@ export default class CategoryService {
success: true, success: true,
status: HttpStatusEnum.OK, status: HttpStatusEnum.OK,
message: 'Category updated.', message: 'Category updated.',
data, data: category,
}; };
} }
} }

View File

@ -6,7 +6,7 @@ export default class UpdateCategoryValidator {
public schema = schema.create({ public schema = schema.create({
title: schema.string.optional(), title: schema.string.optional(),
description: schema.string.optional(), description: schema.string.nullableAndOptional(),
}); });
public messages = {}; public messages = {};