대시보드 테이블에 회사 코드 컬럼 추가
This commit is contained in:
@@ -18,7 +18,8 @@ export class DashboardService {
|
||||
*/
|
||||
static async createDashboard(
|
||||
data: CreateDashboardRequest,
|
||||
userId: string
|
||||
userId: string,
|
||||
companyCode?: string
|
||||
): Promise<Dashboard> {
|
||||
const dashboardId = uuidv4();
|
||||
const now = new Date();
|
||||
@@ -31,8 +32,8 @@ export class DashboardService {
|
||||
`
|
||||
INSERT INTO dashboards (
|
||||
id, title, description, is_public, created_by,
|
||||
created_at, updated_at, tags, category, view_count, settings
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
|
||||
created_at, updated_at, tags, category, view_count, settings, company_code
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)
|
||||
`,
|
||||
[
|
||||
dashboardId,
|
||||
@@ -46,6 +47,7 @@ export class DashboardService {
|
||||
data.category || null,
|
||||
0,
|
||||
JSON.stringify(data.settings || {}),
|
||||
companyCode || "DEFAULT",
|
||||
]
|
||||
);
|
||||
|
||||
@@ -143,7 +145,11 @@ export class DashboardService {
|
||||
/**
|
||||
* 대시보드 목록 조회
|
||||
*/
|
||||
static async getDashboards(query: DashboardListQuery, userId?: string) {
|
||||
static async getDashboards(
|
||||
query: DashboardListQuery,
|
||||
userId?: string,
|
||||
companyCode?: string
|
||||
) {
|
||||
const {
|
||||
page = 1,
|
||||
limit = 20,
|
||||
@@ -161,6 +167,13 @@ export class DashboardService {
|
||||
let params: any[] = [];
|
||||
let paramIndex = 1;
|
||||
|
||||
// 회사 코드 필터링 (최우선)
|
||||
if (companyCode) {
|
||||
whereConditions.push(`d.company_code = $${paramIndex}`);
|
||||
params.push(companyCode);
|
||||
paramIndex++;
|
||||
}
|
||||
|
||||
// 권한 필터링
|
||||
if (userId) {
|
||||
whereConditions.push(
|
||||
@@ -278,7 +291,8 @@ export class DashboardService {
|
||||
*/
|
||||
static async getDashboardById(
|
||||
dashboardId: string,
|
||||
userId?: string
|
||||
userId?: string,
|
||||
companyCode?: string
|
||||
): Promise<Dashboard | null> {
|
||||
try {
|
||||
// 1. 대시보드 기본 정보 조회 (권한 체크 포함)
|
||||
@@ -286,21 +300,43 @@ export class DashboardService {
|
||||
let dashboardParams: any[];
|
||||
|
||||
if (userId) {
|
||||
dashboardQuery = `
|
||||
SELECT d.*
|
||||
FROM dashboards d
|
||||
WHERE d.id = $1 AND d.deleted_at IS NULL
|
||||
AND (d.created_by = $2 OR d.is_public = true)
|
||||
`;
|
||||
dashboardParams = [dashboardId, userId];
|
||||
if (companyCode) {
|
||||
dashboardQuery = `
|
||||
SELECT d.*
|
||||
FROM dashboards d
|
||||
WHERE d.id = $1 AND d.deleted_at IS NULL
|
||||
AND d.company_code = $2
|
||||
AND (d.created_by = $3 OR d.is_public = true)
|
||||
`;
|
||||
dashboardParams = [dashboardId, companyCode, userId];
|
||||
} else {
|
||||
dashboardQuery = `
|
||||
SELECT d.*
|
||||
FROM dashboards d
|
||||
WHERE d.id = $1 AND d.deleted_at IS NULL
|
||||
AND (d.created_by = $2 OR d.is_public = true)
|
||||
`;
|
||||
dashboardParams = [dashboardId, userId];
|
||||
}
|
||||
} else {
|
||||
dashboardQuery = `
|
||||
SELECT d.*
|
||||
FROM dashboards d
|
||||
WHERE d.id = $1 AND d.deleted_at IS NULL
|
||||
AND d.is_public = true
|
||||
`;
|
||||
dashboardParams = [dashboardId];
|
||||
if (companyCode) {
|
||||
dashboardQuery = `
|
||||
SELECT d.*
|
||||
FROM dashboards d
|
||||
WHERE d.id = $1 AND d.deleted_at IS NULL
|
||||
AND d.company_code = $2
|
||||
AND d.is_public = true
|
||||
`;
|
||||
dashboardParams = [dashboardId, companyCode];
|
||||
} else {
|
||||
dashboardQuery = `
|
||||
SELECT d.*
|
||||
FROM dashboards d
|
||||
WHERE d.id = $1 AND d.deleted_at IS NULL
|
||||
AND d.is_public = true
|
||||
`;
|
||||
dashboardParams = [dashboardId];
|
||||
}
|
||||
}
|
||||
|
||||
const dashboardResult = await PostgreSQLService.query(
|
||||
|
||||
Reference in New Issue
Block a user