diff --git a/app/Models/Category.ts b/app/Models/Category.ts index 2f7a4fb..9bd6696 100644 --- a/app/Models/Category.ts +++ b/app/Models/Category.ts @@ -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; diff --git a/app/Repositories/CategoryRepository.ts b/app/Repositories/CategoryRepository.ts index 2361e76..3a16555 100644 --- a/app/Repositories/CategoryRepository.ts +++ b/app/Repositories/CategoryRepository.ts @@ -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; } diff --git a/app/Services/CategoryService.ts b/app/Services/CategoryService.ts index bb72edd..cfe78b0 100644 --- a/app/Services/CategoryService.ts +++ b/app/Services/CategoryService.ts @@ -144,7 +144,7 @@ export default class CategoryService { success: true, status: HttpStatusEnum.OK, message: 'Category updated.', - data, + data: category, }; } } diff --git a/app/Validators/Category/UpdateCategoryValidator.ts b/app/Validators/Category/UpdateCategoryValidator.ts index fbfb94b..6dff15e 100644 --- a/app/Validators/Category/UpdateCategoryValidator.ts +++ b/app/Validators/Category/UpdateCategoryValidator.ts @@ -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 = {};