- B01 프로젝트 수정: 과업책임자·분야별책임자·설계자를 회사 구성원 목록(select)에서 지정. 회사 로고·설계자 서명 칸은 누르면 등록 목록 모달(선택·삭제·신규 추가 업로드). - 백엔드: `company_assets`(013) CRUD 라우트 신설 — 목록·업로드(Form+File, 2MB·확장자 검사)·수정·소프트 삭제·파일 서빙. `_scope_company` 로 SYSTEM_ADMIN 만 타 회사 지정, `_check_project_refs` 로 담당자·자산이 같은 회사·같은 종류인지 검사(400). - projects 조회·수정에 pm/field_lead/designer/logo_asset/signature_asset 5칸 합류. 중복 3곳을 `_project_rows` 로 묶어 700줄 제한 유지. - B07 표제란: 로고·서명 출처를 `companies.logo_path`/`users.signature_path` 에서 프로젝트가 고른 `company_assets` 로 전환(삭제된 자산은 그림째 제외). - 검증: pytest 143 통과(신규 4), tsc·ruff·prettier 통과. 공용 브라우저 사용자 경로 (업로드→선택→저장→재열기) 및 종단도 API 표제란 글자 4건·그림 2건 수치 확인. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
388 lines
12 KiB
TypeScript
388 lines
12 KiB
TypeScript
import { API_BASE_URL } from "@config/config_frontend";
|
|
|
|
export interface DashboardUser {
|
|
id: number;
|
|
email: string;
|
|
name: string;
|
|
position?: string | null;
|
|
department?: string | null;
|
|
phone?: string | null;
|
|
company_id?: number | null;
|
|
company_name?: string | null;
|
|
role: "SYSTEM_ADMIN" | "ADMIN" | "USER";
|
|
is_master: boolean;
|
|
status: string;
|
|
/** 서버가 하드 삭제 모드인지 (`PROJECT_DELETE_HARD_ENABLED`). GET /me에서만 채워진다. */
|
|
project_delete_hard?: boolean;
|
|
}
|
|
|
|
export interface WorkflowStageState {
|
|
stage_no: number;
|
|
stage_key: string;
|
|
state: "NOT_STARTED" | "IN_PROGRESS" | "COMPLETE" | "FAILED" | "STALE";
|
|
progress_percent: number;
|
|
params?: any | null;
|
|
message?: string | null;
|
|
started_at?: string | null;
|
|
completed_at?: string | null;
|
|
}
|
|
|
|
export interface WorkflowState {
|
|
project_id: string;
|
|
current_stage: number;
|
|
stages: WorkflowStageState[];
|
|
}
|
|
|
|
export interface ProjectItem {
|
|
id: string;
|
|
company_id?: number | null;
|
|
name: string;
|
|
region?: string | null;
|
|
road_type?: string | null;
|
|
project_year?: number | null;
|
|
estimated_length_m?: number | null;
|
|
memo?: string | null;
|
|
status?: string | null;
|
|
/** 도면 표제란·표지에 실리는 값 — 프로그램이 지어낼 수 없어 사람이 넣는다 */
|
|
client_org?: string | null;
|
|
project_number?: string | null;
|
|
work_amount?: string | null;
|
|
design_date?: string | null;
|
|
/** 담당자는 회사 구성원(users.id), 로고·서명은 회사 공유 자산(company_assets.id) */
|
|
pm_user_id?: number | null;
|
|
field_lead_user_id?: number | null;
|
|
designer_user_id?: number | null;
|
|
logo_asset_id?: number | null;
|
|
signature_asset_id?: number | null;
|
|
owner_name?: string | null;
|
|
workflow_stage: number;
|
|
progress_percent: number;
|
|
workflow_state?: WorkflowState;
|
|
updated_at?: string | null;
|
|
}
|
|
|
|
export interface CompanyInfo {
|
|
id: number;
|
|
name: string;
|
|
business_registration_number?: string | null;
|
|
business_address?: string | null;
|
|
business_owner?: string | null;
|
|
business_status?: string | null;
|
|
user_count?: number;
|
|
project_count?: number;
|
|
}
|
|
|
|
export interface Member {
|
|
id: number;
|
|
email: string;
|
|
name: string;
|
|
position?: string | null;
|
|
department?: string | null;
|
|
role: string;
|
|
status: string;
|
|
}
|
|
|
|
/** 회사 안에서 공유하는 도면 자산(로고·서명). user_id 가 없으면 회사 공용. */
|
|
export interface CompanyAsset {
|
|
id: number;
|
|
company_id: number;
|
|
kind: "LOGO" | "SIGNATURE";
|
|
label: string;
|
|
user_id?: number | null;
|
|
user_name?: string | null;
|
|
}
|
|
|
|
export interface JoinRequest {
|
|
id: number;
|
|
user_id: number;
|
|
company_id: number;
|
|
user_email: string;
|
|
user_name?: string | null;
|
|
company_name?: string | null;
|
|
requested_at: string;
|
|
status: string;
|
|
}
|
|
|
|
export interface AuditLog {
|
|
id: number;
|
|
user_id: number;
|
|
email?: string | null;
|
|
action: string;
|
|
resource_type?: string | null;
|
|
resource_id?: number | null;
|
|
timestamp: string;
|
|
}
|
|
|
|
export interface ResourceSnapshot {
|
|
cpu_usage_percent: number | null;
|
|
memory_usage_percent: number | null;
|
|
disk_usage_percent: number | null;
|
|
active_user_count: number;
|
|
active_project_count: number;
|
|
total_storage_mb: number;
|
|
}
|
|
|
|
export interface ResourceHistoryPoint {
|
|
timestamp: string;
|
|
cpu_usage_percent: number | null;
|
|
memory_usage_percent: number | null;
|
|
disk_usage_percent: number | null;
|
|
active_user_count: number;
|
|
active_project_count: number;
|
|
total_storage_mb: number;
|
|
}
|
|
|
|
export interface ResourceData {
|
|
current: ResourceSnapshot;
|
|
history: ResourceHistoryPoint[];
|
|
stats: ResourceSnapshot;
|
|
}
|
|
|
|
export interface UpdateUserRequest {
|
|
name: string;
|
|
position?: string | null;
|
|
department?: string | null;
|
|
phone?: string | null;
|
|
}
|
|
|
|
export interface UpdateProjectRequest {
|
|
name: string;
|
|
region?: string | null;
|
|
road_type?: string | null;
|
|
project_year?: number | null;
|
|
estimated_length_m?: number | null;
|
|
memo?: string | null;
|
|
status?: string | null;
|
|
client_org?: string | null;
|
|
project_number?: string | null;
|
|
work_amount?: string | null;
|
|
design_date?: string | null;
|
|
pm_user_id?: number | null;
|
|
field_lead_user_id?: number | null;
|
|
designer_user_id?: number | null;
|
|
logo_asset_id?: number | null;
|
|
signature_asset_id?: number | null;
|
|
}
|
|
|
|
export interface AdminUpdateUserRequest extends UpdateUserRequest {
|
|
status?: string | null;
|
|
}
|
|
|
|
export interface CreateCompanyRequest {
|
|
name: string;
|
|
business_registration_number: string;
|
|
business_address?: string | null;
|
|
business_owner?: string | null;
|
|
}
|
|
|
|
export interface ChangePasswordRequest {
|
|
current_password: string;
|
|
new_password: string;
|
|
new_password_confirm: string;
|
|
logout_all: boolean;
|
|
}
|
|
|
|
async function request<T>(path: string, init: RequestInit = {}): Promise<T> {
|
|
const response = await fetch(`${API_BASE_URL}${path}`, {
|
|
credentials: "include",
|
|
headers: { "Content-Type": "application/json", ...(init.headers ?? {}) },
|
|
...init,
|
|
});
|
|
const data = (await response.json()) as { detail?: string } & T;
|
|
if (!response.ok) throw new Error(data.detail ?? "Request failed");
|
|
return data;
|
|
}
|
|
|
|
const body = (value: object): string => JSON.stringify(value);
|
|
|
|
export async function fetchDashboardMe(): Promise<DashboardUser> {
|
|
const data = await request<{ user: DashboardUser }>("/dashboard/me");
|
|
return data.user;
|
|
}
|
|
|
|
export async function updateUserProfile(payload: UpdateUserRequest): Promise<DashboardUser> {
|
|
const data = await request<{ user: DashboardUser }>("/dashboard/me", {
|
|
method: "PATCH",
|
|
body: body(payload),
|
|
});
|
|
return data.user;
|
|
}
|
|
|
|
export function changePassword(payload: ChangePasswordRequest): Promise<unknown> {
|
|
return request("/auth/password", {
|
|
method: "POST",
|
|
body: body(payload),
|
|
});
|
|
}
|
|
|
|
export async function fetchUserProjects(): Promise<ProjectItem[]> {
|
|
const data = await request<{ projects: ProjectItem[] }>("/dashboard/user/projects");
|
|
return data.projects;
|
|
}
|
|
|
|
export async function fetchUserCompany(): Promise<CompanyInfo | null> {
|
|
const data = await request<{ company: CompanyInfo | null }>("/dashboard/user/company");
|
|
return data.company;
|
|
}
|
|
|
|
export async function searchCompanies(query: string): Promise<CompanyInfo[]> {
|
|
const data = await request<{ companies: CompanyInfo[] }>(
|
|
`/dashboard/user/companies?q=${encodeURIComponent(query)}`,
|
|
);
|
|
return data.companies;
|
|
}
|
|
|
|
export function createCompany(payload: CreateCompanyRequest): Promise<unknown> {
|
|
return request("/dashboard/user/company/create", { method: "POST", body: body(payload) });
|
|
}
|
|
|
|
export function createSystemCompany(payload: CreateCompanyRequest): Promise<unknown> {
|
|
return request("/dashboard/admin/companies", { method: "POST", body: body(payload) });
|
|
}
|
|
|
|
export function joinCompany(companyId: number): Promise<unknown> {
|
|
return request("/dashboard/user/company/join", {
|
|
method: "POST",
|
|
body: body({ company_id: companyId }),
|
|
});
|
|
}
|
|
|
|
const companyQuery = (companyId?: number | null): string =>
|
|
companyId ? `?company_id=${encodeURIComponent(companyId)}` : "";
|
|
|
|
/** companyId 는 시스템관리자가 남의 회사 프로젝트를 고칠 때만 넘긴다. */
|
|
export async function fetchCompanyMembers(companyId?: number | null): Promise<Member[]> {
|
|
const data = await request<{ members: Member[] }>(
|
|
`/dashboard/admin/members${companyQuery(companyId)}`,
|
|
);
|
|
return data.members;
|
|
}
|
|
|
|
export async function fetchCompanyAssets(companyId?: number | null): Promise<CompanyAsset[]> {
|
|
const data = await request<{ assets: CompanyAsset[] }>(
|
|
`/dashboard/company/assets${companyQuery(companyId)}`,
|
|
);
|
|
return data.assets;
|
|
}
|
|
|
|
/** multipart 업로드라 `request()`의 JSON 헤더를 쓰지 않는다. */
|
|
export async function createCompanyAsset(form: FormData): Promise<number> {
|
|
const response = await fetch(`${API_BASE_URL}/dashboard/company/assets`, {
|
|
method: "POST",
|
|
credentials: "include",
|
|
body: form,
|
|
});
|
|
const data = (await response.json()) as { detail?: string; asset_id: number };
|
|
if (!response.ok) throw new Error(data.detail ?? "Request failed");
|
|
return data.asset_id;
|
|
}
|
|
|
|
export function deleteCompanyAsset(assetId: number): Promise<unknown> {
|
|
return request(`/dashboard/company/assets/${assetId}`, { method: "DELETE" });
|
|
}
|
|
|
|
export const companyAssetFileUrl = (assetId: number): string =>
|
|
`${API_BASE_URL}/dashboard/company/assets/${assetId}/file`;
|
|
|
|
export function addCompanyMember(email: string): Promise<unknown> {
|
|
return request("/dashboard/admin/members", { method: "POST", body: body({ email }) });
|
|
}
|
|
|
|
export function removeCompanyMember(userId: number): Promise<unknown> {
|
|
return request(`/dashboard/admin/members/${userId}`, { method: "DELETE" });
|
|
}
|
|
|
|
export async function fetchCompanyJoinRequests(): Promise<JoinRequest[]> {
|
|
const data = await request<{ requests: JoinRequest[] }>("/dashboard/admin/join-requests");
|
|
return data.requests;
|
|
}
|
|
|
|
export function processJoinRequest(
|
|
requestId: number,
|
|
action: "APPROVE" | "REJECT",
|
|
): Promise<unknown> {
|
|
return request(`/dashboard/admin/join-requests/${requestId}`, {
|
|
method: "PATCH",
|
|
body: body({ action }),
|
|
});
|
|
}
|
|
|
|
export async function fetchCompanyProjects(): Promise<ProjectItem[]> {
|
|
const data = await request<{ projects: ProjectItem[] }>("/dashboard/admin/projects");
|
|
return data.projects;
|
|
}
|
|
|
|
export async function fetchAllProjects(): Promise<ProjectItem[]> {
|
|
const data = await request<{ projects: ProjectItem[] }>("/dashboard/admin/projects-all");
|
|
return data.projects;
|
|
}
|
|
|
|
export async function fetchAllCompanies(): Promise<CompanyInfo[]> {
|
|
const data = await request<{ companies: CompanyInfo[] }>("/dashboard/admin/companies");
|
|
return data.companies;
|
|
}
|
|
|
|
export async function fetchAllUsers(): Promise<DashboardUser[]> {
|
|
const data = await request<{ users: DashboardUser[] }>("/dashboard/admin/users");
|
|
return data.users;
|
|
}
|
|
|
|
export function changeUserRole(userId: number, role: string): Promise<unknown> {
|
|
return request(`/dashboard/admin/users/${userId}/role`, {
|
|
method: "PATCH",
|
|
body: body({ role }),
|
|
});
|
|
}
|
|
|
|
export function updateProject(projectId: string, payload: UpdateProjectRequest): Promise<unknown> {
|
|
return request(`/dashboard/projects/${encodeURIComponent(projectId)}`, {
|
|
method: "PUT",
|
|
body: body(payload),
|
|
});
|
|
}
|
|
|
|
export function deleteProject(projectId: string): Promise<unknown> {
|
|
return request(`/dashboard/projects/${encodeURIComponent(projectId)}`, { method: "DELETE" });
|
|
}
|
|
|
|
export function updateDashboardUser(
|
|
userId: number,
|
|
payload: AdminUpdateUserRequest,
|
|
): Promise<unknown> {
|
|
return request(`/dashboard/admin/users/${userId}`, {
|
|
method: "PUT",
|
|
body: body(payload),
|
|
});
|
|
}
|
|
|
|
export function assignUserToCompany(userId: number, companyId: number | null): Promise<unknown> {
|
|
return request(`/dashboard/admin/users/${userId}/company`, {
|
|
method: "PATCH",
|
|
body: body({ company_id: companyId }),
|
|
});
|
|
}
|
|
|
|
export async function fetchAllJoinRequests(): Promise<JoinRequest[]> {
|
|
const data = await request<{ requests: JoinRequest[] }>("/dashboard/admin/join-requests-all");
|
|
return data.requests;
|
|
}
|
|
|
|
export function systemApproveJoinRequest(requestId: number): Promise<unknown> {
|
|
return request(`/dashboard/admin/join-requests/${requestId}/approve`, { method: "PATCH" });
|
|
}
|
|
|
|
export async function fetchAuditLogs(): Promise<AuditLog[]> {
|
|
const data = await request<{ items: AuditLog[] }>("/dashboard/admin/audit-logs");
|
|
return data.items;
|
|
}
|
|
|
|
export async function fetchSystemResources(days = 30): Promise<ResourceData> {
|
|
return request<ResourceData>(`/dashboard/admin/resources?days=${encodeURIComponent(days)}`);
|
|
}
|
|
|
|
export function fetchProjectWorkflowState(projectId: string): Promise<WorkflowState> {
|
|
return request(`/projects/${projectId}/workflow-state`, {
|
|
method: "GET",
|
|
}) as Promise<WorkflowState>;
|
|
}
|