-
-
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.
Browse files
Browse the repository at this point in the history
<!--- Please provide a general summary of your changes in the title above --> # Pull Request type <!-- Please try to limit your pull request to one type; submit multiple pull requests if needed. --> Please check the type of change your PR introduces: - [x] Bugfix - [ ] Feature - [ ] Code style update (formatting, renaming) - [ ] Refactoring (no functional changes, no API changes) - [ ] Build-related changes - [ ] Documentation content changes - [ ] Other (please describe): ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> Issue Number: IN-958 ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - - - ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this does introduce a breaking change, please describe the impact and migration path for existing applications below. --> ## Other information <!-- Any other information that is important to this PR, such as screenshots of how the component looks before and after the change. -->
- 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.