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;
@column()
public description: string;
public description: string | null;
@column({ serializeAs: 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 data
@ -79,13 +80,7 @@ export default class CategoryRepository {
const category = await this.Category.query().where('id', id).first();
if (category) {
await category
.merge({
title: data.title,
description: data.description,
})
.save();
await category.merge(data).save();
return category;
}

View File

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

View File

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