mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
keep allowing 0 and convert to null internally
This commit is contained in:
+1
-1
@@ -94,7 +94,7 @@ class AssetBulkUpdateDto {
|
|||||||
|
|
||||||
/// Rating in range [1-5], or null for unrated
|
/// Rating in range [1-5], or null for unrated
|
||||||
///
|
///
|
||||||
/// Minimum value: 1
|
/// Minimum value: 0
|
||||||
/// Maximum value: 5
|
/// Maximum value: 5
|
||||||
int? rating;
|
int? rating;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -79,7 +79,7 @@ class UpdateAssetDto {
|
|||||||
|
|
||||||
/// Rating in range [1-5], or null for unrated
|
/// Rating in range [1-5], or null for unrated
|
||||||
///
|
///
|
||||||
/// Minimum value: 1
|
/// Minimum value: 0
|
||||||
/// Maximum value: 5
|
/// Maximum value: 5
|
||||||
int? rating;
|
int? rating;
|
||||||
|
|
||||||
|
|||||||
@@ -15692,7 +15692,7 @@
|
|||||||
"rating": {
|
"rating": {
|
||||||
"description": "Rating in range [1-5], or null for unrated",
|
"description": "Rating in range [1-5], or null for unrated",
|
||||||
"maximum": 5,
|
"maximum": 5,
|
||||||
"minimum": 1,
|
"minimum": 0,
|
||||||
"nullable": true,
|
"nullable": true,
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"x-immich-history": [
|
"x-immich-history": [
|
||||||
@@ -25227,7 +25227,7 @@
|
|||||||
"rating": {
|
"rating": {
|
||||||
"description": "Rating in range [1-5], or null for unrated",
|
"description": "Rating in range [1-5], or null for unrated",
|
||||||
"maximum": 5,
|
"maximum": 5,
|
||||||
"minimum": 1,
|
"minimum": 0,
|
||||||
"nullable": true,
|
"nullable": true,
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"x-immich-history": [
|
"x-immich-history": [
|
||||||
|
|||||||
@@ -214,13 +214,20 @@ describe(AssetController.name, () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should reject invalid rating', async () => {
|
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);
|
const { status, body } = await request(ctx.getHttpServer()).put(`/assets/${factory.uuid()}`).send(test);
|
||||||
expect(status).toBe(400);
|
expect(status).toBe(400);
|
||||||
expect(body).toEqual(factory.responses.badRequest());
|
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 () => {
|
it('should leave correct ratings as-is', async () => {
|
||||||
const assetId = factory.uuid();
|
const assetId = factory.uuid();
|
||||||
for (const test of [{ rating: 1 }, { rating: 5 }]) {
|
for (const test of [{ rating: 1 }, { rating: 5 }]) {
|
||||||
|
|||||||
@@ -15,8 +15,9 @@ const UpdateAssetBaseSchema = z
|
|||||||
longitude: longitudeSchema.optional().describe('Longitude coordinate'),
|
longitude: longitudeSchema.optional().describe('Longitude coordinate'),
|
||||||
rating: z
|
rating: z
|
||||||
.int()
|
.int()
|
||||||
.min(1)
|
.min(0)
|
||||||
.max(5)
|
.max(5)
|
||||||
|
.transform((value) => (value === 0 ? null : value))
|
||||||
.nullish()
|
.nullish()
|
||||||
.describe('Rating in range [1-5], or null for unrated')
|
.describe('Rating in range [1-5], or null for unrated')
|
||||||
.meta({
|
.meta({
|
||||||
|
|||||||
Reference in New Issue
Block a user