-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backend): add updating organizations endpoint
- Loading branch information
Showing
15 changed files
with
131 additions
and
54 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
44 changes: 44 additions & 0 deletions
44
apps/backend/src/modules/api/helpers/map-tag-to-sdk-errors.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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { taskEither as TE } from 'fp-ts'; | ||
import { pipe } from 'fp-ts/function'; | ||
|
||
import type { TaggedError } from '@llm/commons'; | ||
|
||
import { isSdkTaggedError, SdkRecordAlreadyExistsError, SdkRecordNotFoundError } from '@llm/sdk'; | ||
import { DatabaseRecordAlreadyExists, DatabaseRecordNotExists } from '~/modules/database'; | ||
import { LoggerService } from '~/modules/logger'; | ||
|
||
export function mapTagToSdkError<const ET extends string, RET extends TaggedError<`Sdk${string}`>>( | ||
catchTag: ET, | ||
mapper: (err: TaggedError<string>) => RET, | ||
) { | ||
const logger = LoggerService.of('mapTagToSdkError'); | ||
|
||
return <T, E extends TaggedError<string, any>>(task: TE.TaskEither<E, T>) => pipe( | ||
task, | ||
TE.mapLeft((error) => { | ||
if (isSdkTaggedError(error) || error.tag !== catchTag) { | ||
return error; | ||
} | ||
|
||
const { stack, ...context } = error; | ||
|
||
logger.error(`Mapped creator SDK error - ${error.tag}!`, context); | ||
|
||
if (stack) { | ||
console.error(stack); | ||
} | ||
|
||
return mapper(error); | ||
}), | ||
) as TE.TaskEither<Exclude<E, TaggedError<ET>> | RET, T>; | ||
} | ||
|
||
export const mapDbRecordAlreadyExistsToSdkError = mapTagToSdkError( | ||
DatabaseRecordAlreadyExists.tag, | ||
() => new SdkRecordAlreadyExistsError({}), | ||
); | ||
|
||
export const mapDbRecordNotFoundToSdkError = mapTagToSdkError( | ||
DatabaseRecordNotExists.tag, | ||
() => new SdkRecordNotFoundError({}), | ||
); |
45 changes: 0 additions & 45 deletions
45
apps/backend/src/modules/api/helpers/reject-unsafe-create-sdk-errors.ts
This file was deleted.
Oops, something went wrong.
4 changes: 3 additions & 1 deletion
4
apps/backend/src/modules/database/errors/database-record-already-exists.error.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,3 +1,5 @@ | ||
import { TaggedError } from '@llm/commons'; | ||
|
||
export class DatabaseRecordAlreadyExists extends TaggedError.ofLiteral()('DatabaseRecordAlreadyExists') {} | ||
export class DatabaseRecordAlreadyExists extends TaggedError.ofLiteral()('DatabaseRecordAlreadyExists') { | ||
readonly httpCode = 403; | ||
} |
4 changes: 3 additions & 1 deletion
4
apps/backend/src/modules/database/errors/database-record-not-exists.error.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,3 +1,5 @@ | ||
import { TaggedError } from '@llm/commons'; | ||
|
||
export class DatabaseRecordNotExists extends TaggedError.ofLiteral()('DatabaseRecordNotExists') {} | ||
export class DatabaseRecordNotExists extends TaggedError.ofLiteral()('DatabaseRecordNotExists') { | ||
readonly httpCode = 404; | ||
} |
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
17 changes: 17 additions & 0 deletions
17
packages/sdk/src/modules/dashboard/organizations/dto/sdk-update-organization.dto.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { z } from 'zod'; | ||
|
||
import { SdkTableRowWithIdV, ZodOmitArchivedFields, ZodOmitDateFields } from '~/shared'; | ||
|
||
import { SdkOrganizationV } from './sdk-organization.dto'; | ||
|
||
export const SdkUpdateOrganizationInputV = SdkOrganizationV.omit({ | ||
...ZodOmitDateFields, | ||
...ZodOmitArchivedFields, | ||
id: true, | ||
}); | ||
|
||
export type SdkUpdateOrganizationInputT = z.infer<typeof SdkUpdateOrganizationInputV>; | ||
|
||
export const SdkUpdateOrganizationOutputV = SdkTableRowWithIdV; | ||
|
||
export type SdkUpdateOrganizationOutputT = z.infer<typeof SdkUpdateOrganizationOutputV>; |
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,6 +1,7 @@ | ||
export * from './is-sdk-tagged-error'; | ||
export * from './sdk-payload-validation.error'; | ||
export * from './sdk-record-already-exists.error'; | ||
export * from './sdk-record-not-found.error'; | ||
export * from './sdk-request.error'; | ||
export * from './sdk-server.error'; | ||
export * from './sdk-unauthorized.error'; |
4 changes: 3 additions & 1 deletion
4
packages/sdk/src/shared/errors/sdk-record-already-exists.error.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,3 +1,5 @@ | ||
import { TaggedError } from '@llm/commons'; | ||
|
||
export class SdkRecordAlreadyExistsError extends TaggedError.ofLiteral()('SdkRecordAlreadyExistsError') {} | ||
export class SdkRecordAlreadyExistsError extends TaggedError.ofLiteral()('SdkRecordAlreadyExistsError') { | ||
static readonly httpCode = 403; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { TaggedError } from '@llm/commons'; | ||
|
||
export class SdkRecordNotFoundError extends TaggedError.ofLiteral()('SdkRecordNotFoundError') { | ||
readonly httpCode = 404; | ||
} |