-
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(sdk): add users groups sdk utils
- Loading branch information
Showing
9 changed files
with
172 additions
and
0 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
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,4 @@ | ||
export * from './sdk-create-users-group.dto'; | ||
export * from './sdk-search-users-groups.dto'; | ||
export * from './sdk-update-users-group.dto'; | ||
export * from './sdk-users-group.dto'; |
24 changes: 24 additions & 0 deletions
24
packages/sdk/src/modules/dashboard/users-groups/dto/sdk-create-users-group.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,24 @@ | ||
import { z } from 'zod'; | ||
|
||
import { SdkTableRowWithIdV, ZodOmitArchivedFields, ZodOmitDateFields } from '~/shared'; | ||
|
||
import { SdkUsersGroupV } from './sdk-users-group.dto'; | ||
|
||
export const SdkCreateUsersGroupInputV = SdkUsersGroupV | ||
.omit({ | ||
...ZodOmitDateFields, | ||
...ZodOmitArchivedFields, | ||
id: true, | ||
organization: true, | ||
creator: true, | ||
}) | ||
.extend({ | ||
organization: SdkTableRowWithIdV, | ||
users: z.array(SdkTableRowWithIdV), | ||
}); | ||
|
||
export type SdkCreateUsersGroupInputT = z.infer<typeof SdkCreateUsersGroupInputV>; | ||
|
||
export const SdkCreateUsersGroupOutputV = SdkTableRowWithIdV; | ||
|
||
export type SdkCreateUsersGroupOutputT = z.infer<typeof SdkCreateUsersGroupOutputV>; |
34 changes: 34 additions & 0 deletions
34
packages/sdk/src/modules/dashboard/users-groups/dto/sdk-search-users-groups.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,34 @@ | ||
import type { z } from 'zod'; | ||
|
||
import { | ||
SdkArchivedFiltersInputV, | ||
SdkDefaultSortInputV, | ||
SdkExcludeIdsFiltersInputV, | ||
SdkFilteredPhraseInputV, | ||
SdkIdsArrayV, | ||
SdkIdsFiltersInputV, | ||
SdkOffsetPaginationInputV, | ||
SdkOffsetPaginationOutputV, | ||
} from '~/shared'; | ||
|
||
import { SdkUsersGroupV } from './sdk-users-group.dto'; | ||
|
||
export const SdkSearchUsersGroupItemV = SdkUsersGroupV; | ||
|
||
export type SdkSearchUsersGroupItemT = z.infer<typeof SdkSearchUsersGroupItemV>; | ||
|
||
export const SdKSearchUsersGroupsInputV = SdkOffsetPaginationInputV | ||
.extend({ | ||
organizationIds: SdkIdsArrayV.optional(), | ||
}) | ||
.merge(SdkDefaultSortInputV) | ||
.merge(SdkArchivedFiltersInputV) | ||
.merge(SdkIdsFiltersInputV) | ||
.merge(SdkExcludeIdsFiltersInputV) | ||
.merge(SdkFilteredPhraseInputV); | ||
|
||
export type SdKSearchUsersGroupsInputT = z.infer<typeof SdKSearchUsersGroupsInputV>; | ||
|
||
export const SdKSearchUsersGroupsOutputV = SdkOffsetPaginationOutputV(SdkSearchUsersGroupItemV); | ||
|
||
export type SdkSearchUsersGroupsOutputT = z.infer<typeof SdKSearchUsersGroupsOutputV>; |
19 changes: 19 additions & 0 deletions
19
packages/sdk/src/modules/dashboard/users-groups/dto/sdk-update-users-group.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,19 @@ | ||
import type { z } from 'zod'; | ||
|
||
import { SdkTableRowWithIdV, ZodOmitArchivedFields, ZodOmitDateFields } from '~/shared'; | ||
|
||
import { SdkUsersGroupV } from './sdk-users-group.dto'; | ||
|
||
export const SdkUpdateUsersGroupInputV = SdkUsersGroupV.omit({ | ||
...ZodOmitDateFields, | ||
...ZodOmitArchivedFields, | ||
id: true, | ||
organization: true, | ||
creator: true, | ||
}); | ||
|
||
export type SdkUpdateUsersGroupInputT = z.infer<typeof SdkUpdateUsersGroupInputV>; | ||
|
||
export const SdkUpdateUsersGroupOutputV = SdkTableRowWithIdV; | ||
|
||
export type SdkUpdateUsersGroupOutputT = z.infer<typeof SdkUpdateUsersGroupOutputV>; |
21 changes: 21 additions & 0 deletions
21
packages/sdk/src/modules/dashboard/users-groups/dto/sdk-users-group.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,21 @@ | ||
import { z } from 'zod'; | ||
|
||
import { | ||
SdkIdNameUrlEntryV, | ||
SdkTableRowWithArchivedV, | ||
SdkTableRowWithDatesV, | ||
SdkTableRowWithIdNameV, | ||
} from '~/shared'; | ||
|
||
import { SdkUserListItemV } from '../../users/dto/sdk-user-list-item.dto'; | ||
|
||
export const SdkUsersGroupV = z.strictObject({ | ||
organization: SdkIdNameUrlEntryV, | ||
creator: SdkUserListItemV, | ||
users: z.array(SdkUserListItemV), | ||
}) | ||
.merge(SdkTableRowWithIdNameV) | ||
.merge(SdkTableRowWithDatesV) | ||
.merge(SdkTableRowWithArchivedV); | ||
|
||
export type SdkUsersGroupT = z.infer<typeof SdkUsersGroupV>; |
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,2 @@ | ||
export * from './dto'; | ||
export * from './users-groups.sdk'; |
64 changes: 64 additions & 0 deletions
64
packages/sdk/src/modules/dashboard/users-groups/users-groups.sdk.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,64 @@ | ||
import { AbstractNestedSdkWithAuth } from '~/modules/abstract-nested-sdk-with-auth'; | ||
import { | ||
getPayload, | ||
patchPayload, | ||
postPayload, | ||
putPayload, | ||
type SdkRecordAlreadyExistsError, | ||
type SdkRecordNotFoundError, | ||
type SdkTableRowIdT, | ||
type SdkTableRowWithIdT, | ||
} from '~/shared'; | ||
|
||
import type { | ||
SdkCreateUsersGroupInputT, | ||
SdkCreateUsersGroupOutputT, | ||
SdKSearchUsersGroupsInputT, | ||
SdkSearchUsersGroupsOutputT, | ||
SdkUpdateUsersGroupInputT, | ||
SdkUpdateUsersGroupOutputT, | ||
} from './dto'; | ||
|
||
export class UsersGroupsSdk extends AbstractNestedSdkWithAuth { | ||
protected endpointPrefix = '/dashboard/users/groups'; | ||
|
||
search = (data: SdKSearchUsersGroupsInputT) => | ||
this.fetch<SdkSearchUsersGroupsOutputT>({ | ||
url: this.endpoint('/search'), | ||
query: data, | ||
options: getPayload(), | ||
}); | ||
|
||
create = (data: SdkCreateUsersGroupInputT) => | ||
this.fetch<SdkCreateUsersGroupOutputT, SdkRecordAlreadyExistsError>({ | ||
url: this.endpoint('/'), | ||
options: postPayload(data), | ||
}); | ||
|
||
unarchive = (id: SdkTableRowIdT) => | ||
this.fetch< | ||
SdkTableRowWithIdT, | ||
SdkRecordNotFoundError | SdkRecordAlreadyExistsError | ||
>({ | ||
url: this.endpoint(`/unarchive/${id}`), | ||
options: patchPayload({}), | ||
}); | ||
|
||
archive = (id: SdkTableRowIdT) => | ||
this.fetch< | ||
SdkTableRowWithIdT, | ||
SdkRecordNotFoundError | SdkRecordAlreadyExistsError | ||
>({ | ||
url: this.endpoint(`/archive/${id}`), | ||
options: patchPayload({}), | ||
}); | ||
|
||
update = ({ id, ...data }: SdkUpdateUsersGroupInputT & SdkTableRowWithIdT) => | ||
this.fetch< | ||
SdkUpdateUsersGroupOutputT, | ||
SdkRecordAlreadyExistsError | SdkRecordNotFoundError | ||
>({ | ||
url: this.endpoint(`/${id}`), | ||
options: putPayload(data), | ||
}); | ||
}; |