mirror of
https://github.com/sergeyyarkov/educt-server.git
synced 2026-10-11 10:19:20 +03:00
fix: fixed category updating
This commit is contained in:
parent
bac861a09d
commit
6248134614
@ -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;
|
||||||
|
|||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 = {};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user