Skip to content

Commit

Permalink
feat(sdk): add users groups sdk utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Mati365 committed Dec 29, 2024
1 parent ad5c315 commit 0b3c0b1
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/sdk/src/modules/dashboard/dashboard.sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ import { ProjectsEmbeddingsSdk } from './projects-embeddings';
import { ProjectsFilesSdk } from './projects-files';
import { S3BucketsSdk } from './s3-buckets';
import { UsersSdk } from './users';
import { UsersGroupsSdk } from './users-groups';

export class DashboardSdk {
public readonly organizations = new OrganizationsSdk(this.config);

public readonly users = new UsersSdk(this.config);

public readonly usersGroups = new UsersGroupsSdk(this.config);

public readonly projects = new ProjectsSdk(this.config);

public readonly projectsFiles = new ProjectsFilesSdk(this.config);
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/modules/dashboard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export * from './projects-policies';
export * from './s3-buckets';
export * from './s3-files';
export * from './users';
export * from './users-groups';
4 changes: 4 additions & 0 deletions packages/sdk/src/modules/dashboard/users-groups/dto/index.ts
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';
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>;
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>;
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>;
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>;
2 changes: 2 additions & 0 deletions packages/sdk/src/modules/dashboard/users-groups/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './dto';
export * from './users-groups.sdk';
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),
});
};

0 comments on commit 0b3c0b1

Please sign in to comment.