-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into search-page-alerts
- Loading branch information
Showing
15 changed files
with
244 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,38 @@ | ||
import * as R from 'remeda' | ||
|
||
import { getAuditedClient } from '@weareinreach/db' | ||
import { type TRPCHandlerParams } from '~api/types/handler' | ||
|
||
import { type TUpdateSchema } from './mutation.update.schema' | ||
|
||
export const update = async ({ ctx, input }: TRPCHandlerParams<TUpdateSchema, 'protected'>) => { | ||
const { where, data } = input | ||
const prisma = getAuditedClient(ctx.actorId) | ||
const updated = await prisma.orgWebsite.update({ | ||
const { | ||
where, | ||
data, | ||
}) | ||
return updated | ||
data: { url }, | ||
} = input | ||
console.log(input) | ||
if (R.isString(url)) { | ||
const { locations, ...rest } = data | ||
const upserted = await prisma.orgWebsite.upsert({ | ||
where, | ||
create: { | ||
id: where.id, | ||
url, | ||
...(locations && { locations: { create: locations.upsert.create } }), | ||
...rest, | ||
}, | ||
update: data, | ||
}) | ||
|
||
return upserted | ||
} else { | ||
const updated = await prisma.orgWebsite.update({ | ||
where, | ||
data, | ||
}) | ||
return updated | ||
} | ||
} | ||
export default update |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 13 additions & 16 deletions
29
packages/api/router/orgWebsite/query.forEditDrawer.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,22 @@ | ||
import { prisma } from '@weareinreach/db' | ||
import { handleError } from '~api/lib/errorHandler' | ||
import { type TRPCHandlerParams } from '~api/types/handler' | ||
|
||
import { type TForEditDrawerSchema } from './query.forEditDrawer.schema' | ||
|
||
export const forEditDrawer = async ({ input }: TRPCHandlerParams<TForEditDrawerSchema>) => { | ||
try { | ||
const result = await prisma.orgWebsite.findUnique({ | ||
where: input, | ||
include: { | ||
description: { include: { tsKey: true } }, | ||
}, | ||
}) | ||
if (!result) return null | ||
const reformatted = { | ||
...result, | ||
description: result.description?.tsKey?.text, | ||
} | ||
return reformatted | ||
} catch (error) { | ||
handleError(error) | ||
const result = await prisma.orgWebsite.findUnique({ | ||
where: input, | ||
include: { | ||
description: { include: { tsKey: true } }, | ||
}, | ||
}) | ||
if (!result) { | ||
return null | ||
} | ||
const reformatted = { | ||
...result, | ||
description: result.description?.tsKey?.text, | ||
} | ||
return reformatted | ||
} | ||
export default forEditDrawer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.