keep allowing 0 and convert to null internally

This commit is contained in:
Mees Frensel 2026-04-23 15:06:57 +02:00
parent 2325a359a6
commit f16a83f65b
5 changed files with 14 additions and 6 deletions

View File

@ -94,7 +94,7 @@ class AssetBulkUpdateDto {
/// Rating in range [1-5], or null for unrated
///
/// Minimum value: 1
/// Minimum value: 0
/// Maximum value: 5
int? rating;

View File

@ -79,7 +79,7 @@ class UpdateAssetDto {
/// Rating in range [1-5], or null for unrated
///
/// Minimum value: 1
/// Minimum value: 0
/// Maximum value: 5
int? rating;

View File

@ -15692,7 +15692,7 @@
"rating": {
"description": "Rating in range [1-5], or null for unrated",
"maximum": 5,
"minimum": 1,
"minimum": 0,
"nullable": true,
"type": "integer",
"x-immich-history": [
@ -25227,7 +25227,7 @@
"rating": {
"description": "Rating in range [1-5], or null for unrated",
"maximum": 5,
"minimum": 1,
"minimum": 0,
"nullable": true,
"type": "integer",
"x-immich-history": [

View File

@ -214,13 +214,20 @@ describe(AssetController.name, () => {
});
it('should reject invalid rating', async () => {
for (const test of [{ rating: 0 }, { rating: 7 }, { rating: 3.5 }, { rating: -2 }]) {
for (const test of [{ rating: 7 }, { rating: 3.5 }, { rating: -2 }]) {
const { status, body } = await request(ctx.getHttpServer()).put(`/assets/${factory.uuid()}`).send(test);
expect(status).toBe(400);
expect(body).toEqual(factory.responses.badRequest());
}
});
it('should convert rating 0 to null', async () => {
const assetId = factory.uuid();
const { status } = await request(ctx.getHttpServer()).put(`/assets/${assetId}`).send({ rating: 0 });
expect(service.update).toHaveBeenCalledWith(undefined, assetId, { rating: null });
expect(status).toBe(200);
});
it('should leave correct ratings as-is', async () => {
const assetId = factory.uuid();
for (const test of [{ rating: 1 }, { rating: 5 }]) {

View File

@ -15,8 +15,9 @@ const UpdateAssetBaseSchema = z
longitude: longitudeSchema.optional().describe('Longitude coordinate'),
rating: z
.int()
.min(1)
.min(0)
.max(5)
.transform((value) => (value === 0 ? null : value))
.nullish()
.describe('Rating in range [1-5], or null for unrated')
.meta({