@@ -15,10 +15,7 @@ import { prismaClient as prismaDm } from "~prisma-schemas/schemas/dm/client";
1515
1616import type { UserServices } from "../../../index" ;
1717import { getShownQuotations } from "../../coa/quotations" ;
18- import {
19- checkPurchaseIdsBelongToUser ,
20- deleteIssues ,
21- } from "./util" ;
18+ import { checkPurchaseIdsBelongToUser , deleteIssues } from "./util" ;
2219
2320export 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