-
-
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.
- Loading branch information
Showing
6 changed files
with
213 additions
and
135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,27 @@ | ||
import { addSingleKey } from '@weareinreach/crowdin/api' | ||
import { getAuditedClient } from '@weareinreach/db' | ||
import { type TRPCHandlerParams } from '~api/types/handler' | ||
|
||
import { type TCreateSchema } from './mutation.create.schema' | ||
|
||
const create = async ({ ctx, input }: TRPCHandlerParams<TCreateSchema, 'protected'>) => { | ||
const prisma = getAuditedClient(ctx.actorId) | ||
const newEmail = await prisma.orgEmail.create({ | ||
data: input, | ||
select: { id: true }, | ||
|
||
const result = await prisma.$transaction(async (tx) => { | ||
if (input.description) { | ||
const crowdinId = await addSingleKey({ | ||
isDatabaseString: true, | ||
key: input.description.create.tsKey.create.key, | ||
text: input.description.create.tsKey.create.text, | ||
}) | ||
input.description.create.tsKey.create.crowdinId = crowdinId.id | ||
} | ||
const newEmail = await tx.orgEmail.create({ | ||
data: input, | ||
select: { id: true }, | ||
}) | ||
return newEmail | ||
}) | ||
return newEmail | ||
return result | ||
} | ||
export default create |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,42 @@ | ||
import invariant from 'tiny-invariant' | ||
|
||
import { addSingleKey } from '@weareinreach/crowdin/api' | ||
import { getAuditedClient } from '@weareinreach/db' | ||
import { type TRPCHandlerParams } from '~api/types/handler' | ||
|
||
import { type TCreateSchema } from './mutation.create.schema' | ||
|
||
const create = async ({ ctx, input }: TRPCHandlerParams<TCreateSchema, 'protected'>) => { | ||
const prisma = getAuditedClient(ctx.actorId) | ||
const newPhone = await prisma.orgPhone.create({ | ||
data: input, | ||
select: { id: true }, | ||
|
||
const result = await prisma.$transaction(async (tx) => { | ||
if (input.description) { | ||
const crowdinDesc = await addSingleKey({ | ||
isDatabaseString: true, | ||
key: input.description.create.tsKey.create.key, | ||
text: input.description.create.tsKey.create.text, | ||
}) | ||
input.description.create.tsKey.create.crowdinId = crowdinDesc.id | ||
} | ||
if (input.phoneType?.create) { | ||
invariant( | ||
input.phoneType.create.key?.create && input.phoneType.create.key.create.namespace?.connect?.name | ||
) | ||
const crowdinPhoneType = await addSingleKey({ | ||
isDatabaseString: false, | ||
key: input.phoneType.create.key.create.key, | ||
text: input.phoneType.create.key.create.text, | ||
ns: input.phoneType.create.key.create.namespace.connect.name as 'phone-type', | ||
}) | ||
input.phoneType.create.key.create.crowdinId = crowdinPhoneType.id | ||
} | ||
|
||
const newPhone = await tx.orgPhone.create({ | ||
data: input, | ||
select: { id: true }, | ||
}) | ||
return newPhone | ||
}) | ||
return newPhone | ||
return result | ||
} | ||
export default create |
Oops, something went wrong.