Skip to content

Commit 4653e30

Browse files
cleanup
1 parent 6ae0402 commit 4653e30

File tree

8 files changed

+68
-36
lines changed

8 files changed

+68
-36
lines changed

mobile/openapi/lib/model/tag_update_dto.dart

Lines changed: 14 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

open-api/immich-openapi-specs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13766,6 +13766,7 @@
1376613766
"type": "string"
1376713767
},
1376813768
"name": {
13769+
"nullable": true,
1376913770
"type": "string"
1377013771
}
1377113772
},

open-api/typescript-sdk/src/fetch-client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,7 @@ export type TagBulkAssetsResponseDto = {
14061406
};
14071407
export type TagUpdateDto = {
14081408
color?: string | null;
1409+
name?: string | null;
14091410
};
14101411
export type TimeBucketResponseDto = {
14111412
count: number;

server/src/dtos/tag.dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class TagCreateDto {
1919
export class TagUpdateDto {
2020
@IsString()
2121
@Optional({ emptyToNull: true, nullable: true })
22-
name?: string;
22+
name?: string | null;
2323

2424
@Optional({ emptyToNull: true, nullable: true })
2525
@ValidateHexColor()

server/src/queries/tag.repository.sql

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- NOTE: This file is auto generated by ./sql-generator
22

3-
-- TagRepository.get
3+
-- TagRepository.getOne
44
select
55
"tags"."id",
66
"tags"."value",
@@ -13,6 +13,19 @@ from
1313
where
1414
"id" = $1
1515

16+
-- TagRepository.getMany
17+
select
18+
"tags"."id",
19+
"tags"."value",
20+
"tags"."createdAt",
21+
"tags"."updatedAt",
22+
"tags"."color",
23+
"tags"."parentId"
24+
from
25+
"tags"
26+
where
27+
"id" in $1
28+
1629
-- TagRepository.getByValue
1730
select
1831
"tags"."id",
@@ -61,27 +74,46 @@ order by
6174
"value" asc
6275

6376
-- TagRepository.create
77+
begin
6478
insert into
6579
"tags" ("userId", "color", "value")
6680
values
6781
($1, $2, $3)
6882
returning
6983
*
84+
rollback
7085

7186
-- TagRepository.update
87+
begin
7288
update "tags"
7389
set
74-
"color" = $1
90+
"value" = $1,
91+
"color" = $2
7592
where
76-
"id" = $2
93+
"id" = $3
7794
returning
7895
*
96+
rollback
7997

8098
-- TagRepository.delete
8199
delete from "tags"
82100
where
83101
"id" = $1
84102

103+
-- TagRepository.deleteEmptyTags
104+
begin
105+
select
106+
"tags"."id",
107+
count("assets"."id") as "count"
108+
from
109+
"assets"
110+
inner join "tag_asset" on "tag_asset"."assetsId" = "assets"."id"
111+
inner join "tags_closure" on "tags_closure"."id_descendant" = "tag_asset"."tagsId"
112+
inner join "tags" on "tags"."id" = "tags_closure"."id_descendant"
113+
group by
114+
"tags"."id"
115+
commit
116+
85117
-- TagRepository.addAssetIds
86118
insert into
87119
"tag_asset" ("tagsId", "assetsId")
@@ -107,17 +139,3 @@ on conflict do nothing
107139
returning
108140
*
109141
rollback
110-
111-
-- TagRepository.deleteEmptyTags
112-
begin
113-
select
114-
"tags"."id",
115-
count("assets"."id") as "count"
116-
from
117-
"assets"
118-
inner join "tag_asset" on "tag_asset"."assetsId" = "assets"."id"
119-
inner join "tags_closure" on "tags_closure"."id_descendant" = "tag_asset"."tagsId"
120-
inner join "tags" on "tags"."id" = "tags_closure"."id_descendant"
121-
group by
122-
"tags"."id"
123-
commit

server/src/repositories/tag.repository.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ export class TagRepository {
7777
if (dto.value) {
7878
// propagate value update downstream
7979
const descendantIds = await this.getDescendantIds(id);
80-
const descendants = await this.getMany(descendantIds.filter(_id => _id !== id));
81-
const childrenByParentId = new Map<string, { id: string, value: string }[]>();
80+
const descendants = await this.getMany(descendantIds.filter((_id) => _id !== id));
81+
const childrenByParentId = new Map<string, { id: string; value: string }[]>();
8282
for (const descendant of descendants) {
8383
const parentId = descendant.parentId;
8484
if (parentId) {
@@ -89,7 +89,7 @@ export class TagRepository {
8989
}
9090
}
9191

92-
const queue: { id: string; value: string }[] = [{id, value: updated.value}];
92+
const queue: { id: string; value: string }[] = [{ id, value: updated.value }];
9393
for (let i = 0; i < queue.length; i++) {
9494
const { id, value } = queue[i];
9595
const children = childrenByParentId.get(id) ?? [];
@@ -98,26 +98,26 @@ export class TagRepository {
9898
const item = { id: child.id, value: `${value}/${name}` };
9999
queue.push(item);
100100
}
101-
}
101+
}
102102

103-
const toUpdate = queue.slice(1);
104-
if (toUpdate.length > 0) {
105-
await sql`
103+
const toUpdate = queue.slice(1);
104+
if (toUpdate.length > 0) {
105+
await sql`
106106
UPDATE tags
107107
SET value = updates.value
108108
FROM (
109109
VALUES
110110
${sql.join(
111-
toUpdate.map(u => sql`(${sql`${u.id}::uuid`}, ${u.value})`),
112-
sql`, `
111+
toUpdate.map((u) => sql`(${sql`${u.id}::uuid`}, ${u.value})`),
112+
sql`, `,
113113
)}
114114
) AS updates(id, value)
115115
WHERE tags.id = updates.id
116116
`.execute(tx);
117-
};
117+
}
118118
}
119119
});
120-
120+
121121
return updated!;
122122
}
123123

@@ -232,10 +232,10 @@ export class TagRepository {
232232
.where('id_ancestor', '=', ancestorId)
233233
.execute();
234234

235-
return results.map(r => r.id_descendant);
235+
return results.map((r) => r.id_descendant);
236236
}
237237

238-
async updateTagClosures(tag: { id: string, parentId?: string | null }, tx: Transaction<DB>) {
238+
async updateTagClosures(tag: { id: string; parentId?: string | null }, tx: Transaction<DB>) {
239239
// update closure table
240240
await tx
241241
.insertInto('tags_closure')

server/src/services/tag.service.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ describe(TagService.name, () => {
113113
it('should update a tag', async () => {
114114
mocks.access.tag.checkOwnerAccess.mockResolvedValue(new Set(['tag-1']));
115115
mocks.tag.update.mockResolvedValue(tagStub.colorCreate);
116+
mocks.tag.getOne.mockResolvedValue(tagStub.tag);
116117
await expect(sut.update(authStub.admin, 'tag-1', { color: '#000000' })).resolves.toEqual(tagResponseStub.color1);
117118
expect(mocks.tag.update).toHaveBeenCalledWith('tag-1', { color: '#000000' });
118119
});

server/src/services/tag.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ export class TagService extends BaseService {
6868

6969
let value;
7070
if (name) {
71-
const parts = existing.value.split("/");
71+
const parts = existing.value.split('/');
7272
parts[parts.length - 1] = name;
73-
value = parts.join("/");
73+
value = parts.join('/');
7474
}
7575

7676
const tag = await this.tagRepository.update(id, { value, color });

0 commit comments

Comments
 (0)