Merge branch '16680-expired-token-handling'
[arvados.git] / src / services / tag-service / tag-service.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { LinkService } from "../link-service/link-service";
6 import { LinkClass } from "~/models/link";
7 import { FilterBuilder } from "~/services/api/filter-builder";
8 import { TagTailType, TagResource } from "~/models/tag";
9 import { OrderBuilder } from "~/services/api/order-builder";
10
11 export class TagService {
12
13     constructor(private linkService: LinkService) { }
14
15     create(uuid: string, data: { key: string; value: string } ) {
16         return this.linkService
17             .create({
18                 headUuid: uuid,
19                 tailUuid: TagTailType.COLLECTION,
20                 linkClass: LinkClass.TAG,
21                 name: '',
22                 properties: data
23             })
24             .then(tag => tag as TagResource );
25     }
26
27     list(uuid: string) {
28         const filters = new FilterBuilder()
29             .addEqual("head_uuid", uuid)
30             .addEqual("tail_uuid", TagTailType.COLLECTION)
31             .addEqual("link_class", LinkClass.TAG)
32             .getFilters();
33
34         const order = new OrderBuilder<TagResource>()
35             .addAsc('createdAt')
36             .getOrder();
37
38         return this.linkService
39             .list({ filters, order })
40             .then(results => {
41                 return results.items.map((tag => tag as TagResource ));
42             });
43     }
44 }