Skip to content

Commit

Permalink
Feat: add templates UI
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithmullapudi committed Jan 8, 2025
1 parent e048c65 commit c06d1da
Show file tree
Hide file tree
Showing 108 changed files with 1,270 additions and 1,442 deletions.
2 changes: 1 addition & 1 deletion apps/server/src/modules/action/action.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class ActionGuard implements CanActivate {
return false;
}

const workspace = await this.workspaceService.getWorkspace({ workspaceId });
const workspace = await this.workspaceService.getWorkspace(workspaceId);
return workspace.actionsEnabled;
}
}
6 changes: 3 additions & 3 deletions apps/server/src/modules/cycles/cycles.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Body, Controller, Param, Post, UseGuards } from '@nestjs/common';
import { UpdateCycleDateDto } from '@tegonhq/types';
import { UpdateCycleDto } from '@tegonhq/types';

import { AuthGuard } from 'modules/auth/auth.guard';
import { AdminGuard } from 'modules/users/admin.guard';
Expand All @@ -21,9 +21,9 @@ export class CyclesController {

@Post(':cycleId')
@UseGuards(AuthGuard, AdminGuard)
async updateCycleDate(
async updateCycle(
@Param('cycleId') cycleId: string,
@Body() cycleData: UpdateCycleDateDto,
@Body() cycleData: UpdateCycleDto,
) {
return await this.cycles.updateCycleDates(cycleId, cycleData);
}
Expand Down
12 changes: 9 additions & 3 deletions apps/server/src/modules/cycles/cycles.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
Cycle,
CycleStatusEnum,
TeamPreferenceDto,
UpdateCycleDateDto,
UpdateCycleDto,
} from '@tegonhq/types';
import { PrismaService } from 'nestjs-prisma';

Expand Down Expand Up @@ -65,9 +65,13 @@ export class CyclesService {

async updateCycleDates(
cycleId: string,
updateCycleDates: UpdateCycleDateDto,
updateCycleDates: UpdateCycleDto,
): Promise<Cycle[]> {
const { startDate: startDateStr, endDate: endDateStr } = updateCycleDates;
const {
startDate: startDateStr,
endDate: endDateStr,
description,
} = updateCycleDates;
const startDate = startDateStr ? new Date(startDateStr) : undefined;
const endDate = endDateStr ? new Date(endDateStr) : undefined;

Expand All @@ -83,6 +87,7 @@ export class CyclesService {
data: {
...(startDate && { startDate }),
...(endDate && { endDate }),
description,
},
});
return [cycle];
Expand Down Expand Up @@ -111,6 +116,7 @@ export class CyclesService {
data: {
...(startDate && { startDate }),
...(endDate && { endDate }),
description,
},
}),
// Update all subsequent cycles
Expand Down
37 changes: 20 additions & 17 deletions apps/server/src/modules/templates/templates.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ import {
Query,
UseGuards,
} from '@nestjs/common';
import { Template } from '@tegonhq/types';
import { SessionContainer } from 'supertokens-node/recipe/session';
import {
CreateTemplateDto,
Template,
TemplateIdDto,
UpdateTemplateDto,
} from '@tegonhq/types';

import { AuthGuard } from 'modules/auth/auth.guard';
import { Session as SessionDecorator } from 'modules/auth/session.decorator';
import { UserId, Workspace } from 'modules/auth/session.decorator';

import {
CreateTemplateInput,
UpdateTemplateInput,
TemplateRequestIdParams,
RequestIdParams,
} from './templates.interface';
import { RequestIdParams } from './templates.interface';
import TemplatesService from './templates.service';

@Controller({
Expand All @@ -32,11 +31,15 @@ export class TemplatesController {
@Post()
@UseGuards(AuthGuard)
async createTemplate(
@SessionDecorator() session: SessionContainer,
@Body() templateData: CreateTemplateInput,
@UserId() userId: string,
@Workspace() workspaceId: string,
@Body() templateData: CreateTemplateDto,
): Promise<Template> {
const userId = session.getUserId();
return await this.templatesService.createTemplate(userId, templateData);
return await this.templatesService.createTemplate(
userId,
workspaceId,
templateData,
);
}

@Get()
Expand All @@ -51,7 +54,7 @@ export class TemplatesController {
@UseGuards(AuthGuard)
async getTemplate(
@Param()
templateId: TemplateRequestIdParams,
templateId: TemplateIdDto,
): Promise<Template> {
return await this.templatesService.getTemplate(templateId);
}
Expand All @@ -60,8 +63,8 @@ export class TemplatesController {
@UseGuards(AuthGuard)
async updateTemplate(
@Param()
templateId: TemplateRequestIdParams,
@Body() templateData: UpdateTemplateInput,
templateId: TemplateIdDto,
@Body() templateData: UpdateTemplateDto,
): Promise<Template> {
return await this.templatesService.updateTemplate(templateId, templateData);
}
Expand All @@ -70,7 +73,7 @@ export class TemplatesController {
@UseGuards(AuthGuard)
async deleteLabel(
@Param()
templateId: TemplateRequestIdParams,
templateId: TemplateIdDto,
): Promise<Template> {
return await this.templatesService.deleteTemplate(templateId);
}
Expand Down
37 changes: 1 addition & 36 deletions apps/server/src/modules/templates/templates.interface.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,4 @@
import { TemplateCategoryEnum } from '@tegonhq/types';
import { IsEnum, IsOptional, IsString } from 'class-validator';

export class CreateTemplateInput {
@IsString()
name: string;

@IsEnum(TemplateCategoryEnum)
category: TemplateCategoryEnum;

// TODO: Manoj change this when you have finalised the issue thing
// eslint-disable-next-line @typescript-eslint/no-explicit-any
templateData: Record<string, any>;

@IsString()
workspaceId: string;

@IsOptional()
@IsString()
teamId?: string;
}

export class UpdateTemplateInput {
@IsOptional()
@IsString()
name?: string;

// TODO: Manoj change this when you have finalised the issue thing
// eslint-disable-next-line @typescript-eslint/no-explicit-any
templateData: Record<string, any>;
}

export class TemplateRequestIdParams {
@IsString()
templateId: string;
}
import { IsOptional, IsString } from 'class-validator';

export class RequestIdParams {
@IsOptional()
Expand Down
32 changes: 16 additions & 16 deletions apps/server/src/modules/templates/templates.service.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import { Injectable } from '@nestjs/common';
import { Template } from '@tegonhq/types';
import {
CreateTemplateDto,
Template,
TemplateIdDto,
UpdateTemplateDto,
} from '@tegonhq/types';
import { PrismaService } from 'nestjs-prisma';

import {
CreateTemplateInput,
UpdateTemplateInput,
TemplateRequestIdParams,
RequestIdParams,
} from './templates.interface';
import { RequestIdParams } from './templates.interface';

@Injectable()
export default class TemplatesService {
constructor(private prisma: PrismaService) {}

async createTemplate(
userId: string,
templateData: CreateTemplateInput,
workspaceId: string,
templateData: CreateTemplateDto,
): Promise<Template> {
const template = await this.prisma.template.create({
data: {
...templateData,
workspaceId,
createdById: userId,
},
});
Expand All @@ -41,31 +43,29 @@ export default class TemplatesService {
});
}

async getTemplate(
TemplateRequestIdParams: TemplateRequestIdParams,
): Promise<Template> {
async getTemplate(templateRequestIdParams: TemplateIdDto): Promise<Template> {
return await this.prisma.template.findUnique({
where: {
id: TemplateRequestIdParams.templateId,
id: templateRequestIdParams.templateId,
},
});
}

async updateTemplate(
TemplateRequestIdParams: TemplateRequestIdParams,
templateData: UpdateTemplateInput,
templateRequestIdParams: TemplateIdDto,
templateData: UpdateTemplateDto,
): Promise<Template> {
return await this.prisma.template.update({
data: {
...templateData,
},
where: {
id: TemplateRequestIdParams.templateId,
id: templateRequestIdParams.templateId,
},
});
}

async deleteTemplate(templateRequestIdParams: TemplateRequestIdParams) {
async deleteTemplate(templateRequestIdParams: TemplateIdDto) {
return await this.prisma.template.update({
where: {
id: templateRequestIdParams.templateId,
Expand Down
7 changes: 0 additions & 7 deletions apps/server/src/modules/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,6 @@ export class UsersController {
return this.users.impersonate(key, userId, res, req);
}

@Get('email')
@UseGuards(AuthGuard)
async getUserByEmail(@Query('email') email: string): Promise<User> {
const user = await this.users.getUserByEmail(email);
return user;
}

@Post('pat')
@UseGuards(AuthGuard)
async createPersonalAccessToken(
Expand Down
61 changes: 19 additions & 42 deletions apps/server/src/modules/workspaces/workspaces.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,6 @@ export class WorkspacesController {
return await this.workspacesService.getAllWorkspaces(userId);
}

@Get('name/:workspaceName')
@UseGuards(AuthGuard)
async getWorkspaceByName(
@Param('workspaceName') workspaceName: string,
): Promise<Workspace> {
return await this.workspacesService.getWorkspaceByName(workspaceName);
}

@Get('slug/:workspaceSlug')
@UseGuards(AuthGuard)
async getWorkspaceBySlug(
@Param('workspaceSlug') workspaceSlug: string,
): Promise<Workspace> {
return await this.workspacesService.getWorkspaceBySlug(workspaceSlug);
}

@Post('invite_action')
@UseGuards(AuthGuard)
async inviteAction(
Expand All @@ -100,12 +84,9 @@ export class WorkspacesController {
);
}

@Get(':workspaceId')
@Get()
@UseGuards(AuthGuard)
async getWorkspace(
@Param()
workspaceId: WorkspaceRequestParamsDto,
): Promise<Workspace> {
async getWorkspace(@WorkspaceD() workspaceId: string): Promise<Workspace> {
return await this.workspacesService.getWorkspace(workspaceId);
}

Expand All @@ -121,11 +102,22 @@ export class WorkspacesController {
);
}

@Post(':workspaceId')
@Post('add_users')
@UseGuards(AuthGuard)
async addUserToWorkspace(
@WorkspaceD() workspaceId: string,
@Body() UserBody: UserBody,
): Promise<UsersOnWorkspaces> {
return await this.workspacesService.addUserToWorkspace(
workspaceId,
UserBody.userId,
);
}

@Post()
@UseGuards(AuthGuard)
async updateWorkspace(
@Param()
workspaceId: WorkspaceRequestParamsDto,
@WorkspaceD() workspaceId: string,
@Body() workspaceData: UpdateWorkspaceInput,
): Promise<Workspace> {
return await this.workspacesService.updateWorkspace(
Expand All @@ -134,28 +126,13 @@ export class WorkspacesController {
);
}

@Delete(':workspaceId')
@Delete()
@UseGuards(AuthGuard)
async deleteWorkspace(
@Param()
workspaceId: WorkspaceRequestParamsDto,
): Promise<Workspace> {
async deleteWorkspace(@WorkspaceD() workspaceId: string): Promise<Workspace> {
return await this.workspacesService.deleteWorkspace(workspaceId);
}

@Post(':workspaceId/add_users')
@UseGuards(AuthGuard)
async addUserToWorkspace(
@Param() WorkspaceRequestParamsDto: WorkspaceRequestParamsDto,
@Body() UserBody: UserBody,
): Promise<UsersOnWorkspaces> {
return await this.workspacesService.addUserToWorkspace(
WorkspaceRequestParamsDto.workspaceId,
UserBody.userId,
);
}

@Get(':workspaceId/invites')
@Get('invites')
@UseGuards(AuthGuard)
async invitedUsers(
@Param() WorkspaceRequestParamsDto: WorkspaceRequestParamsDto,
Expand Down
Loading

0 comments on commit c06d1da

Please sign in to comment.