Match desktop/mobile mockups and compute current amounts, status, and KPIs from real CRM data. Co-authored-by: Cursor <cursoragent@cursor.com>
133 lines
2.8 KiB
TypeScript
133 lines
2.8 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
Patch,
|
|
Post,
|
|
Query,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
import { CurrentUser } from '../auth/current-user.decorator';
|
|
import {
|
|
CreateSalesGoalDto,
|
|
ForecastQueryDto,
|
|
ListGoalsQueryDto,
|
|
UpdateSalesGoalDto,
|
|
} from './dto';
|
|
import { SalesService } from './sales.service';
|
|
|
|
@Controller('sales')
|
|
@UseGuards(JwtAuthGuard)
|
|
export class SalesController {
|
|
constructor(private readonly salesService: SalesService) {}
|
|
|
|
@Get('forecast')
|
|
forecast(
|
|
@CurrentUser()
|
|
user: { userId: string; organizationId: string; role: string },
|
|
@Query() query: ForecastQueryDto,
|
|
) {
|
|
return this.salesService.forecast(
|
|
{
|
|
userId: user.userId,
|
|
organizationId: user.organizationId,
|
|
role: user.role,
|
|
},
|
|
{ from: query.from, to: query.to, userId: query.userId },
|
|
);
|
|
}
|
|
|
|
@Get('goals')
|
|
listGoals(
|
|
@CurrentUser()
|
|
user: { userId: string; organizationId: string; role: string },
|
|
@Query() query: ListGoalsQueryDto,
|
|
) {
|
|
return this.salesService.listGoals(
|
|
{
|
|
userId: user.userId,
|
|
organizationId: user.organizationId,
|
|
role: user.role,
|
|
},
|
|
{
|
|
from: query.from,
|
|
to: query.to,
|
|
userId: query.userId,
|
|
q: query.q,
|
|
status: query.status,
|
|
type: query.type,
|
|
},
|
|
);
|
|
}
|
|
|
|
@Get('goals/:id')
|
|
getGoal(
|
|
@CurrentUser()
|
|
user: { userId: string; organizationId: string; role: string },
|
|
@Param('id') id: string,
|
|
) {
|
|
return this.salesService.getGoal(
|
|
{
|
|
userId: user.userId,
|
|
organizationId: user.organizationId,
|
|
role: user.role,
|
|
},
|
|
id,
|
|
);
|
|
}
|
|
|
|
@Post('goals')
|
|
createGoal(
|
|
@CurrentUser()
|
|
user: { userId: string; organizationId: string; role: string },
|
|
@Body() dto: CreateSalesGoalDto,
|
|
) {
|
|
return this.salesService.createGoal(
|
|
{
|
|
userId: user.userId,
|
|
organizationId: user.organizationId,
|
|
role: user.role,
|
|
},
|
|
dto,
|
|
);
|
|
}
|
|
|
|
@Patch('goals/:id')
|
|
updateGoal(
|
|
@CurrentUser()
|
|
user: { userId: string; organizationId: string; role: string },
|
|
@Param('id') id: string,
|
|
@Body() dto: UpdateSalesGoalDto,
|
|
) {
|
|
return this.salesService.updateGoal(
|
|
{
|
|
userId: user.userId,
|
|
organizationId: user.organizationId,
|
|
role: user.role,
|
|
},
|
|
id,
|
|
dto,
|
|
);
|
|
}
|
|
|
|
@Delete('goals/:id')
|
|
async removeGoal(
|
|
@CurrentUser()
|
|
user: { userId: string; organizationId: string; role: string },
|
|
@Param('id') id: string,
|
|
) {
|
|
await this.salesService.removeGoal(
|
|
{
|
|
userId: user.userId,
|
|
organizationId: user.organizationId,
|
|
role: user.role,
|
|
},
|
|
id,
|
|
);
|
|
return { ok: true };
|
|
}
|
|
}
|