feat: routines module; super admin subscription badge, 7-day trial and lifetime plan
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Param,
|
||||
Patch,
|
||||
Post,
|
||||
Query,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { OrgModuleGuard } from '../billing/org-module.guard';
|
||||
import { RequireOrgModule } from '../billing/org-module.decorator';
|
||||
import { CurrentUser } from '../auth/current-user.decorator';
|
||||
import type { Actor } from '../common/record-scope';
|
||||
import { RoutinesService } from './routines.service';
|
||||
import { RoutineStatsService } from './routine-stats.service';
|
||||
import {
|
||||
ChangeRoutineAssigneeDto,
|
||||
ListRoutinesQueryDto,
|
||||
RoutineRangeQueryDto,
|
||||
SaveRoutineCategoryDto,
|
||||
SaveRoutineDto,
|
||||
ToggleRoutineDto,
|
||||
} from './dto';
|
||||
|
||||
@Controller('routines')
|
||||
@UseGuards(JwtAuthGuard, OrgModuleGuard)
|
||||
@RequireOrgModule('routines')
|
||||
export class RoutinesController {
|
||||
constructor(
|
||||
private readonly routines: RoutinesService,
|
||||
private readonly stats: RoutineStatsService,
|
||||
) {}
|
||||
|
||||
@Get('context')
|
||||
context(@CurrentUser() user: Actor) {
|
||||
return this.routines.context(user);
|
||||
}
|
||||
|
||||
@Get('categories')
|
||||
categories(@CurrentUser() user: Actor) {
|
||||
return this.routines.categories(user.organizationId);
|
||||
}
|
||||
|
||||
@Post('categories')
|
||||
createCategory(@CurrentUser() user: Actor, @Body() dto: SaveRoutineCategoryDto) {
|
||||
return this.routines.createCategory(user, dto);
|
||||
}
|
||||
|
||||
@Patch('categories/:id')
|
||||
updateCategory(
|
||||
@CurrentUser() user: Actor,
|
||||
@Param('id') id: string,
|
||||
@Body() dto: SaveRoutineCategoryDto,
|
||||
) {
|
||||
return this.routines.updateCategory(user, id, dto);
|
||||
}
|
||||
|
||||
@Delete('categories/:id')
|
||||
deleteCategory(@CurrentUser() user: Actor, @Param('id') id: string) {
|
||||
return this.routines.deleteCategory(user, id);
|
||||
}
|
||||
|
||||
/* ───────── آمار و گزارش ───────── */
|
||||
|
||||
@Get('stats/me')
|
||||
async statsMe(@CurrentUser() user: Actor, @Query() q: RoutineRangeQueryDto) {
|
||||
return this.stats.performance(await this.routines.scope(user), q);
|
||||
}
|
||||
|
||||
@Get('stats/team')
|
||||
async statsTeam(@CurrentUser() user: Actor, @Query() q: RoutineRangeQueryDto) {
|
||||
return this.stats.team(await this.routines.scope(user), q);
|
||||
}
|
||||
|
||||
@Get('stats/weekly')
|
||||
async statsWeekly(@CurrentUser() user: Actor, @Query() q: RoutineRangeQueryDto) {
|
||||
return this.stats.weekly(await this.routines.scope(user), q);
|
||||
}
|
||||
|
||||
@Get('stats/monthly')
|
||||
async statsMonthly(@CurrentUser() user: Actor, @Query() q: RoutineRangeQueryDto) {
|
||||
return this.stats.monthly(await this.routines.scope(user), q);
|
||||
}
|
||||
|
||||
@Get('stats/routines')
|
||||
async statsRoutines(@CurrentUser() user: Actor, @Query() q: RoutineRangeQueryDto) {
|
||||
return this.stats.routinesExecution(await this.routines.scope(user), q);
|
||||
}
|
||||
|
||||
@Get('stats/history')
|
||||
async statsHistory(@CurrentUser() user: Actor, @Query() q: RoutineRangeQueryDto) {
|
||||
return this.stats.history(await this.routines.scope(user), q);
|
||||
}
|
||||
|
||||
/* ───────── روتینها ───────── */
|
||||
|
||||
@Get()
|
||||
list(@CurrentUser() user: Actor, @Query() q: ListRoutinesQueryDto) {
|
||||
return this.routines.list(user, q);
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(@CurrentUser() user: Actor, @Body() dto: SaveRoutineDto) {
|
||||
return this.routines.create(user, dto);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
get(@CurrentUser() user: Actor, @Param('id') id: string) {
|
||||
return this.routines.get(user, id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@CurrentUser() user: Actor, @Param('id') id: string, @Body() dto: SaveRoutineDto) {
|
||||
return this.routines.update(user, id, dto);
|
||||
}
|
||||
|
||||
@Patch(':id/toggle')
|
||||
toggle(@CurrentUser() user: Actor, @Param('id') id: string, @Body() dto: ToggleRoutineDto) {
|
||||
return this.routines.toggle(user, id, dto.isActive);
|
||||
}
|
||||
|
||||
@Patch(':id/assignee')
|
||||
assignee(
|
||||
@CurrentUser() user: Actor,
|
||||
@Param('id') id: string,
|
||||
@Body() dto: ChangeRoutineAssigneeDto,
|
||||
) {
|
||||
return this.routines.changeAssignee(user, id, dto);
|
||||
}
|
||||
|
||||
@Post(':id/duplicate')
|
||||
duplicate(@CurrentUser() user: Actor, @Param('id') id: string) {
|
||||
return this.routines.duplicate(user, id);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@CurrentUser() user: Actor, @Param('id') id: string) {
|
||||
return this.routines.remove(user, id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user