Skip to content

Commit

Permalink
feat: adding groups/create (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
manas-vessel authored Jul 7, 2023
1 parent b6a3539 commit bd4a0b6
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vesselapi/integrations",
"version": "1.0.19",
"version": "1.0.20",
"description": "Vessel integrations",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
3 changes: 2 additions & 1 deletion src/platforms/monday/actions/boards/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ export default action(
const limit = input.limit ?? MONDAY_MAX_PAGE_SIZE;
const page = input.page ?? 1;
const {
data: { data },
data: { data, errors },
$native,
} = await client.boards.list(auth, { limit, page });
const nextPageCursor = (data?.boards.length ?? 0) < limit ? null : page + 1;
return {
boards: data?.boards ?? null,
errors: errors ?? null,
nextPageCursor,
$native,
};
Expand Down
3 changes: 2 additions & 1 deletion src/platforms/monday/actions/graphql/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export default action(
query: input.query,
});
return {
data: data.data,
data: data.data ?? null,
errors: data.errors ?? null,
$native,
};
},
Expand Down
28 changes: 28 additions & 0 deletions src/platforms/monday/actions/groups/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { action } from '@/sdk';
import { z } from 'zod';
import client from '../../client';

export default action(
'groups-create',
{
operation: 'create',
resource: 'groups',
mutation: true,
schema: z.object({
boardId: z.number(),
groupName: z.string(),
}),
scopes: [],
},
async ({ auth, input }) => {
const { data, $native } = await client.groups.create(auth, {
board_id: input.boardId,
group_name: input.groupName,
});
return {
id: data.data?.create_group.id ?? null,
errors: data.errors ?? null,
$native,
};
},
);
1 change: 1 addition & 0 deletions src/platforms/monday/actions/items/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default action(
});
return {
id: data.data?.create_item.id ?? null,
errors: data.errors ?? null,
$native,
};
},
Expand Down
15 changes: 15 additions & 0 deletions src/platforms/monday/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
mondayBoardsFields,
mondayBoardsListResponseSchema,
mondayBoardsRelationalFields,
MondayGroupCreate,
mondayGroupCreateResponseSchema,
MondayItemCreate,
mondayItemCreateResponseSchema,
mondayQueryResponse,
Expand Down Expand Up @@ -44,6 +46,19 @@ const makeClient = () => {
},
})),
},
groups: {
create: request(({ board_id, group_name }: MondayGroupCreate) => ({
url: `/${API_VERSION}`,
method: 'POST',
schema: mondayGroupCreateResponseSchema,
json: {
query: buildCreateQuery({
module: 'groups',
metaFields: shake({ board_id, group_name }),
}),
},
})),
},
items: {
create: request(
({
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/monday/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const API_VERSION = 'v2';
export const BASE_URL = `https://api.monday.com`;
export const MONDAY_MODULES = ['boards', 'items', 'users'] as const;
export const MONDAY_MODULES = ['boards', 'items', 'groups', 'users'] as const;
export const MONDAY_MAX_PAGE_SIZE = 100;
4 changes: 4 additions & 0 deletions src/platforms/monday/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import query from '@/platforms/monday/actions/graphql/query';

import listBoards from '@/platforms/monday/actions/boards/list';

import createGroups from '@/platforms/monday/actions/groups/create';

import createItems from '@/platforms/monday/actions/items/create';

export * as types from './schemas';
Expand All @@ -32,6 +34,8 @@ export default platform('monday', {

listBoards,

createGroups,

createItems,
},
});
20 changes: 11 additions & 9 deletions src/platforms/monday/query-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,26 @@ export function buildCreateQuery({
}: {
module: MondayModule;
metaFields: Record<string, string | number>;
fields: Record<string, string | number>;
fields?: Record<string, string | number>;
}) {
const queryMetaFields = Object.entries(metaFields)
.map(([key, value]) => {
return isNumber(value) ? `${key}: ${value}` : `${key}: "${value}"`;
})
.join(', ');
const queryColumnValues = Object.entries(fields)
.map(([key, value]) => {
return isNumber(value)
? `\\\"${key}\\\": ${value}`
: `\\\"${key}\\\": \\\"${value}\\\"`;
})
.join(', ');
const queryColumnValues =
fields &&
Object.entries(fields)
.map(([key, value]) => {
return isNumber(value)
? `\\\"${key}\\\": ${value}`
: `\\\"${key}\\\": \\\"${value}\\\"`;
})
.join(', ');
return `mutation {
create_${module.replace(/s$/, '')} (
${queryMetaFields},
column_values: "{${queryColumnValues}}"
${fields === undefined ? '' : `column_values: "{${queryColumnValues}}"`}
) {
id
}
Expand Down
20 changes: 19 additions & 1 deletion src/platforms/monday/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { mapValues } from 'radash';
import { z } from 'zod';
import { MONDAY_MODULES } from './constants';

export const mondayQueryResponse = z.object({ data: z.any() });
export const mondayQueryResponse = z.object({
data: z.any().optional(),
errors: z.any().optional(),
});
export type MondayQueryResponse = z.infer<typeof mondayQueryResponse>;

export type MondayModule = (typeof MONDAY_MODULES)[number];
Expand Down Expand Up @@ -52,6 +55,20 @@ export const mondayBoardsListResponseSchema = z.object({
boards: z.array(mondayBoardsSchema),
})
.optional(),
errors: z.any().optional(),
});

// -
// Groups
// -
export const mondayGroupsCreateSchema = z.object({
board_id: z.number(),
group_name: z.string(),
});
export type MondayGroupCreate = z.infer<typeof mondayGroupsCreateSchema>;
export const mondayGroupCreateResponseSchema = z.object({
data: z.object({ create_group: z.object({ id: z.number() }) }).optional(),
errors: z.any().optional(),
});

// -
Expand All @@ -66,4 +83,5 @@ export const mondayItemsCreateSchema = z.object({
export type MondayItemCreate = z.infer<typeof mondayItemsCreateSchema>;
export const mondayItemCreateResponseSchema = z.object({
data: z.object({ create_item: z.object({ id: z.number() }) }).optional(),
errors: z.any().optional(),
});

0 comments on commit bd4a0b6

Please sign in to comment.