Skip to content

Commit dad58ff

Browse files
committed
api: Possibly fix error when deleting issues
1 parent 056df56 commit dad58ff

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

  • packages/api/services/collection/issues

packages/api/services/collection/issues/index.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ import { prismaClient as prismaDm } from "~prisma-schemas/schemas/dm/client";
1515

1616
import type { UserServices } from "../../../index";
1717
import { getShownQuotations } from "../../coa/quotations";
18-
import {
19-
checkPurchaseIdsBelongToUser,
20-
deleteIssues,
21-
} from "./util";
18+
import { checkPurchaseIdsBelongToUser, deleteIssues } from "./util";
2219

2320
export default ({ _socket }: UserServices) => ({
2421
getIssues: async () => {
@@ -44,7 +41,7 @@ export default ({ _socket }: UserServices) => ({
4441
.augmentIssueArrayWithInducksData(
4542
issues as (T & { issuecode: string })[]
4643
)
47-
.then(data => data.filter((issue) => 'publicationcode' in issue))
44+
.then((data) => data.filter((issue) => "publicationcode" in issue))
4845
.then(prismaDm.replaceLabelsWithLabelIds)
4946
);
5047
},
@@ -167,8 +164,11 @@ const addOrChangeIssues = async (
167164
});
168165

169166
const updateOperations = existingIssues.map((existingIssue) => {
170-
const { id, issuecode: _issuecode, ...existingIssueWithoutId } =
171-
existingIssue;
167+
const {
168+
id,
169+
issuecode: _issuecode,
170+
...existingIssueWithoutId
171+
} = existingIssue;
172172
return prismaDm.issue.update({
173173
data: {
174174
...existingIssueWithoutId,
@@ -202,7 +202,7 @@ const addOrChangeIssues = async (
202202
},
203203
})
204204
);
205-
await prismaDm.$transaction(insertOperations);
205+
await prismaDm.$transaction(insertOperations);
206206
// TODO handle labels on multiple issues
207207

208208
// const issueIds = (
@@ -274,11 +274,11 @@ const addOrChangeCopies = async (
274274
},
275275
});
276276
});
277-
await prismaDm.$transaction(operations);
278-
279-
const newIssueLabelsOperations = issueIds
280-
.filter((issueId) => issueId !== null)
281-
.map((issueId, copyNumber) =>
277+
const upsertResults = await prismaDm.$transaction(operations);
278+
const newIssueLabelsOperations = upsertResults
279+
.map((result, copyNumber) => ({ result, copyNumber }))
280+
.filter(({ result }) => "id" in result)
281+
.map(({ result: { id: issueId }, copyNumber }) =>
282282
prismaDm.issueLabel.createMany({
283283
data:
284284
labelIds[copyNumber]?.map((labelId) => ({
@@ -309,7 +309,6 @@ export const resetDemo = async () => {
309309
? "/app/"
310310
: cwd() + "/services/auth/";
311311

312-
313312
const demoUser = (await prismaDm.user.findFirst({
314313
where: { username: "demo" },
315314
}))!;

0 commit comments

Comments
 (0)