feat(sessions): ✨ Add optional corp filter to SessionsQueryDto and sessions.service.ts
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
bca1ceb600
commit
74bc34240e
2 changed files with 25 additions and 1 deletions
|
|
@ -47,6 +47,10 @@ export class SessionsQueryDto {
|
|||
@IsInt()
|
||||
@Min(0)
|
||||
offset?: number = 0;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
corp?: string;
|
||||
}
|
||||
|
||||
export class SessionMetricsQueryDto {
|
||||
|
|
@ -67,4 +71,8 @@ export class SessionMetricsQueryDto {
|
|||
@IsOptional()
|
||||
@IsString()
|
||||
country?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
corp?: string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { InjectDataSource } from '@nestjs/typeorm';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { SessionsQueryDto, SessionMetricsQueryDto, SessionSortBy } from './dto/sessions-query.dto';
|
||||
import { SessionsQueryDto, SessionMetricsQueryDto, SessionSortBy } from "./dto/sessions-query.dto";
|
||||
import { resolveCorpId } from "../common/corp-filter.util";
|
||||
|
||||
export interface SessionRecord {
|
||||
sessionId: string;
|
||||
|
|
@ -83,6 +84,13 @@ export class SessionsService {
|
|||
paramIndex++;
|
||||
}
|
||||
|
||||
const corpId = await resolveCorpId(this.dataSource, query.corp);
|
||||
if (corpId !== null) {
|
||||
conditions.push(`re.corp_id = $${paramIndex}`);
|
||||
params.push(corpId);
|
||||
paramIndex++;
|
||||
}
|
||||
|
||||
const whereClause = conditions.join(' AND ');
|
||||
|
||||
// Map sortBy to column
|
||||
|
|
@ -186,6 +194,14 @@ export class SessionsService {
|
|||
if (country) {
|
||||
conditions.push(`sf.country = $${paramIndex}`);
|
||||
params.push(country);
|
||||
paramIndex++;
|
||||
}
|
||||
|
||||
const corpId = await resolveCorpId(this.dataSource, query.corp);
|
||||
if (corpId !== null) {
|
||||
conditions.push(`re.corp_id = $${paramIndex}`);
|
||||
params.push(corpId);
|
||||
paramIndex++;
|
||||
}
|
||||
|
||||
const whereClause = conditions.join(' AND ');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue