2026-08-29 21:06:30 +03:30
|
|
|
import {
|
|
|
|
|
Body,
|
|
|
|
|
Controller,
|
|
|
|
|
Delete,
|
|
|
|
|
Get,
|
|
|
|
|
Param,
|
|
|
|
|
Patch,
|
|
|
|
|
Post,
|
|
|
|
|
Query,
|
2026-09-15 17:33:05 +03:30
|
|
|
Res,
|
|
|
|
|
StreamableFile,
|
|
|
|
|
UploadedFile,
|
2026-08-29 21:06:30 +03:30
|
|
|
UseGuards,
|
2026-09-15 17:33:05 +03:30
|
|
|
UseInterceptors,
|
2026-08-29 21:06:30 +03:30
|
|
|
} from '@nestjs/common';
|
2026-09-15 17:33:05 +03:30
|
|
|
import { FileInterceptor } from '@nestjs/platform-express';
|
|
|
|
|
import { memoryStorage } from 'multer';
|
|
|
|
|
import type { Response } from 'express';
|
2026-08-29 21:06:30 +03:30
|
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
|
|
|
import { CurrentUser } from '../auth/current-user.decorator';
|
2026-09-15 17:33:05 +03:30
|
|
|
import type { Actor } from '../common/record-scope';
|
2026-08-29 21:06:30 +03:30
|
|
|
import { ActivitiesService } from './activities.service';
|
2026-09-15 17:33:05 +03:30
|
|
|
import { ActivitiesExcelService } from './activities-excel.service';
|
2026-08-29 21:06:30 +03:30
|
|
|
import {
|
|
|
|
|
CreateActivityDto,
|
|
|
|
|
ListActivitiesQueryDto,
|
|
|
|
|
UpdateActivityDto,
|
|
|
|
|
} from './dto';
|
2026-09-15 17:33:05 +03:30
|
|
|
import { brand } from '@mento/shared';
|
2026-08-29 21:06:30 +03:30
|
|
|
|
|
|
|
|
@Controller('activities')
|
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
|
|
|
export class ActivitiesController {
|
2026-09-15 17:33:05 +03:30
|
|
|
constructor(
|
|
|
|
|
private readonly activitiesService: ActivitiesService,
|
|
|
|
|
private readonly excelService: ActivitiesExcelService,
|
|
|
|
|
) {}
|
2026-08-29 21:06:30 +03:30
|
|
|
|
|
|
|
|
@Get('summary')
|
2026-09-15 17:33:05 +03:30
|
|
|
summary(@CurrentUser() user: Actor) {
|
2026-08-29 21:06:30 +03:30
|
|
|
return this.activitiesService.summary(user.organizationId, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get()
|
|
|
|
|
list(
|
2026-09-15 17:33:05 +03:30
|
|
|
@CurrentUser() user: Actor,
|
2026-08-29 21:06:30 +03:30
|
|
|
@Query() query: ListActivitiesQueryDto,
|
|
|
|
|
) {
|
|
|
|
|
return this.activitiesService.list(
|
|
|
|
|
user.organizationId,
|
|
|
|
|
user,
|
|
|
|
|
query.filter ?? 'today',
|
|
|
|
|
query.q,
|
|
|
|
|
query.page ?? 1,
|
|
|
|
|
query.limit ?? 50,
|
|
|
|
|
{
|
|
|
|
|
personId: query.personId,
|
|
|
|
|
companyId: query.companyId,
|
|
|
|
|
dealId: query.dealId,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
from: query.from,
|
|
|
|
|
to: query.to,
|
|
|
|
|
},
|
2026-09-28 12:28:14 +03:30
|
|
|
query.desk,
|
2026-08-29 21:06:30 +03:30
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-15 17:33:05 +03:30
|
|
|
@Get('export')
|
|
|
|
|
async export(
|
|
|
|
|
@CurrentUser() user: Actor,
|
|
|
|
|
@Res({ passthrough: true }) res: Response,
|
|
|
|
|
) {
|
|
|
|
|
const buffer = await this.excelService.export(user);
|
|
|
|
|
res.set({
|
|
|
|
|
'Content-Type':
|
|
|
|
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
|
|
|
'Content-Disposition': `attachment; filename="${brand.filePrefix}-activities.xlsx"`,
|
|
|
|
|
});
|
|
|
|
|
return new StreamableFile(buffer);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-19 15:30:31 +03:30
|
|
|
@Post('import/preview')
|
|
|
|
|
@UseInterceptors(
|
|
|
|
|
FileInterceptor('file', {
|
|
|
|
|
storage: memoryStorage(),
|
|
|
|
|
limits: { fileSize: 15_000_000 },
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
importPreview(@UploadedFile() file: Express.Multer.File) {
|
|
|
|
|
return this.excelService.preview(file);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-15 17:33:05 +03:30
|
|
|
@Post('import')
|
|
|
|
|
@UseInterceptors(
|
|
|
|
|
FileInterceptor('file', {
|
|
|
|
|
storage: memoryStorage(),
|
|
|
|
|
limits: { fileSize: 15_000_000 },
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
import(
|
|
|
|
|
@CurrentUser() user: Actor,
|
|
|
|
|
@UploadedFile() file: Express.Multer.File,
|
2026-09-19 15:30:31 +03:30
|
|
|
@Body('mapping') mapping?: string,
|
2026-09-15 17:33:05 +03:30
|
|
|
) {
|
2026-09-19 15:30:31 +03:30
|
|
|
return this.excelService.import(user, file, mapping);
|
2026-09-15 17:33:05 +03:30
|
|
|
}
|
|
|
|
|
|
2026-08-29 21:06:30 +03:30
|
|
|
@Get(':id')
|
2026-09-15 17:33:05 +03:30
|
|
|
get(@CurrentUser() user: Actor, @Param('id') id: string) {
|
2026-08-29 21:06:30 +03:30
|
|
|
return this.activitiesService.get(user.organizationId, id, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post()
|
2026-09-15 17:33:05 +03:30
|
|
|
create(@CurrentUser() user: Actor, @Body() dto: CreateActivityDto) {
|
2026-08-29 21:06:30 +03:30
|
|
|
return this.activitiesService.create(
|
|
|
|
|
user.organizationId,
|
|
|
|
|
user.userId,
|
|
|
|
|
dto,
|
|
|
|
|
user,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Patch(':id')
|
|
|
|
|
update(
|
2026-09-15 17:33:05 +03:30
|
|
|
@CurrentUser() user: Actor,
|
2026-08-29 21:06:30 +03:30
|
|
|
@Param('id') id: string,
|
|
|
|
|
@Body() dto: UpdateActivityDto,
|
|
|
|
|
) {
|
|
|
|
|
return this.activitiesService.update(user.organizationId, id, user, dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Patch(':id/complete')
|
2026-09-15 17:33:05 +03:30
|
|
|
complete(@CurrentUser() user: Actor, @Param('id') id: string) {
|
2026-08-29 21:06:30 +03:30
|
|
|
return this.activitiesService.complete(user.organizationId, id, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Delete(':id')
|
2026-09-15 17:33:05 +03:30
|
|
|
async remove(@CurrentUser() user: Actor, @Param('id') id: string) {
|
2026-08-29 21:06:30 +03:30
|
|
|
await this.activitiesService.remove(user.organizationId, id, user);
|
|
|
|
|
return { ok: true };
|
|
|
|
|
}
|
|
|
|
|
}
|