From c21ba9e11fbd58039de2ec5e8eb5c578efef3806 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Fri, 22 Dec 2023 17:12:24 +0800 Subject: [PATCH] fix tests --- packages/api/src/repository/label.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/packages/api/src/repository/label.ts b/packages/api/src/repository/label.ts index 6342f3227..ec34560e0 100644 --- a/packages/api/src/repository/label.ts +++ b/packages/api/src/repository/label.ts @@ -73,17 +73,13 @@ export const labelRepository = appDataSource.getRepository(Label).extend({ }, createLabels(labels: CreateLabelInput[], userId: string) { - return this.query( - ` - INSERT INTO omnivore.labels (user_id, name, color, description, internal) - SELECT $1, $2, $3, $4, $5 - WHERE NOT EXISTS ( - SELECT 1 FROM omnivore.labels WHERE LOWER(name) = LOWER($2) AND user_id = $1 - ) - RETURNING id, name, color, description, created_at - `, - labels.map((l) => Object.values(convertToLabel(l, userId))) - ) as Promise + return this.upsert( + labels.map((l) => convertToLabel(l, userId)), + { + conflictPaths: ['name', 'user'], + skipUpdateIfNoValuesChanged: true, + } + ) }, deleteById(id: string) {