Browse Source

Validate tags when creating or updating an activity

pull/7347/head
Thomas Kaul 5 days ago
parent
commit
cc1cec32cc
  1. 4
      apps/api/src/app/account/account.service.ts
  2. 28
      apps/api/src/app/activities/activities.service.ts
  3. 8
      apps/api/src/services/tag/tag.service.ts

4
apps/api/src/app/account/account.service.ts

@ -128,7 +128,7 @@ export class AccountService {
aUserId: string, aUserId: string,
tagIds?: string[] tagIds?: string[]
): Promise<Account> { ): Promise<Account> {
await this.tagService.validateTagIds(tagIds, aUserId); await this.tagService.validateTagIds({ tagIds, userId: aUserId });
const account = await this.prismaService.account.create({ const account = await this.prismaService.account.create({
data: { data: {
@ -268,7 +268,7 @@ export class AccountService {
): Promise<Account> { ): Promise<Account> {
const { data, where } = params; const { data, where } = params;
await this.tagService.validateTagIds(tagIds, aUserId); await this.tagService.validateTagIds({ tagIds, userId: aUserId });
const account = await this.prismaService.account.update({ const account = await this.prismaService.account.update({
data: { data: {

28
apps/api/src/app/activities/activities.service.ts

@ -109,12 +109,12 @@ export class ActivitiesService {
tags, tags,
userId userId
}: { tags: Tag[]; userId: string } & AssetProfileIdentifier) { }: { tags: Tag[]; userId: string } & AssetProfileIdentifier) {
await this.tagService.validateTagIds( await this.tagService.validateTagIds({
tags.map(({ id }) => { userId,
tagIds: tags.map(({ id }) => {
return id; return id;
}), })
userId });
);
const activities = await this.prismaService.order.findMany({ const activities = await this.prismaService.order.findMany({
where: { where: {
@ -164,12 +164,12 @@ export class ActivitiesService {
): Promise<Order> { ): Promise<Order> {
const tags = data.tags ?? []; const tags = data.tags ?? [];
await this.tagService.validateTagIds( await this.tagService.validateTagIds({
tags.map(({ id }) => { tagIds: tags.map(({ id }) => {
return id; return id;
}), }),
data.userId userId: data.userId
); });
let account: Prisma.AccountCreateNestedOneWithoutActivitiesInput; let account: Prisma.AccountCreateNestedOneWithoutActivitiesInput;
@ -965,12 +965,12 @@ export class ActivitiesService {
}): Promise<Order> { }): Promise<Order> {
const tags = data.tags ?? []; const tags = data.tags ?? [];
await this.tagService.validateTagIds( await this.tagService.validateTagIds({
tags.map(({ id }) => { userId,
tagIds: tags.map(({ id }) => {
return id; return id;
}), })
userId });
);
if (!data.comment) { if (!data.comment) {
data.comment = null; data.comment = null;

8
apps/api/src/services/tag/tag.service.ts

@ -126,7 +126,13 @@ export class TagService {
}); });
} }
public async validateTagIds(tagIds: string[], userId: string) { public async validateTagIds({
tagIds,
userId
}: {
tagIds: string[];
userId: string;
}) {
if (!tagIds?.length) { if (!tagIds?.length) {
return; return;
} }

Loading…
Cancel
Save