wcz-layout
Version:
174 lines (173 loc) • 8.15 kB
JavaScript
import { n as serverEnv } from "./env-Dgbk8SQN.js";
import { p as createExternalApi } from "./file-BHdm6ob1.js";
import { a as ResubmitApprovalSchema, i as CreateApprovalSchema, l as ApprovalStepResult, n as ApproveApprovalSchema, o as WithdrawApprovalSchema, r as CancelApprovalSchema, s as ApprovalStatus } from "./Approval-DBjc7AVj.js";
import { z } from "zod";
import { createServerFn, createServerOnlyFn } from "@tanstack/react-start";
//#region src/queries/server/approval.ts
let approvalApi = null;
const getApprovalApi = createServerOnlyFn(() => {
const baseUrl = serverEnv.APPROVAL_BASE_URL;
if (!baseUrl) throw new Error("APPROVAL_BASE_URL is not defined in server environment variables.");
approvalApi ??= createExternalApi(baseUrl, "approval");
return approvalApi;
});
const GetApprovalsSchema = z.object({
appName: z.string().min(1).max(255),
status: ApprovalStatus.optional(),
approverEmployeeId: z.string().min(1).max(20).optional(),
stepResult: ApprovalStepResult.optional()
});
const GetApprovalSchema = z.object({ id: z.uuid() });
const getApprovals = createServerFn({ method: "GET" }).inputValidator(GetApprovalsSchema).handler(async ({ data }) => {
const api = getApprovalApi();
const queryParams = new URLSearchParams();
queryParams.append("applicationName", data.appName);
if (data.status) queryParams.append("status", data.status.toString());
if (data.approverEmployeeId) queryParams.append("approverEmployeeId", data.approverEmployeeId);
if (data.stepResult) queryParams.append("stepResult", data.stepResult.toString());
return api.request({
url: `/Requests/Requests?${queryParams.toString()}`,
method: "GET"
}).then((r) => r.data);
});
const getApproval = createServerFn({ method: "GET" }).inputValidator(GetApprovalSchema).handler(async ({ data }) => {
return getApprovalApi().request({
url: `/Requests/${data.id}`,
method: "GET"
}).then((r) => r.data);
});
const createApproval = createServerFn({ method: "POST" }).inputValidator(CreateApprovalSchema).handler(async ({ data }) => {
return getApprovalApi().request({
url: `/Requests`,
method: "POST",
data
}).then((r) => r.data);
});
const approveApproval = createServerFn({ method: "POST" }).inputValidator(ApproveApprovalSchema).handler(async ({ data }) => {
return getApprovalApi().request({
url: `/Requests/${data.id}/single-approval`,
method: "POST",
data
}).then((r) => r.data);
});
const resubmitApproval = createServerFn({ method: "POST" }).inputValidator(ResubmitApprovalSchema).handler(async ({ data }) => {
return getApprovalApi().request({
url: `/Requests/${data.id}/resubmit`,
method: "POST",
data
}).then((r) => r.data);
});
const withdrawApproval = createServerFn({ method: "POST" }).inputValidator(WithdrawApprovalSchema).handler(async ({ data }) => {
return getApprovalApi().request({
url: `/Requests/${data.id}/withdraw`,
method: "POST",
data
}).then((r) => r.data);
});
const cancelApproval = createServerFn({ method: "POST" }).inputValidator(CancelApprovalSchema).handler(async ({ data }) => {
return getApprovalApi().request({
url: `/Requests/${data.id}/cancel`,
method: "POST",
data
}).then((r) => r.data);
});
//#endregion
//#region src/queries/server/peoplesoft.ts
let peopleSoftApi = null;
const getPeopleSoftApi = createServerOnlyFn(() => {
const baseUrl = serverEnv.PS_BASE_URL;
if (!baseUrl) throw new Error("PS_BASE_URL is not defined in server environment variables.");
peopleSoftApi ??= createExternalApi(baseUrl, "ps");
return peopleSoftApi;
});
const SearchEmployeesSchema = z.object({ searchTerm: z.string().min(1) });
const EmployeeIdSchema = z.object({ employeeId: z.string().min(1) });
const DepartmentIdSchema = z.object({ departmentId: z.string().min(1) });
const CompanyCodeSchema = z.object({ companyCode: z.string().min(1) });
const searchEmployees = createServerFn({ method: "GET" }).inputValidator(SearchEmployeesSchema).handler(async ({ data }) => {
return getPeopleSoftApi().request({
url: `/v1/employee?search=${encodeURIComponent(data.searchTerm)}`,
method: "GET"
}).then((r) => r.data);
});
const getEmployees = createServerFn({ method: "GET" }).handler(async () => {
return getPeopleSoftApi().request({
url: `/v1/employee/all`,
method: "GET"
}).then((r) => r.data);
});
const getActiveEmployees = createServerFn({ method: "GET" }).handler(async () => {
return getPeopleSoftApi().request({
url: `/v1/employee/active`,
method: "GET"
}).then((r) => r.data);
});
const getEmployeeByEmployeeId = createServerFn({ method: "GET" }).inputValidator(EmployeeIdSchema).handler(async ({ data }) => {
return getPeopleSoftApi().request({
url: `/v1/employee/${encodeURIComponent(data.employeeId)}`,
method: "GET"
}).then((r) => r.data);
});
const getPreviousEmployeeIds = createServerFn({ method: "GET" }).handler(async () => {
return getPeopleSoftApi().request({
url: `/v1/employee/previousIds`,
method: "GET"
}).then((r) => r.data);
});
const getEmployeeSupervisor = createServerFn({ method: "GET" }).inputValidator(EmployeeIdSchema).handler(async ({ data }) => {
return getPeopleSoftApi().request({
url: `/v1/employee/${encodeURIComponent(data.employeeId)}/supervisor`,
method: "GET"
}).then((r) => r.data);
});
const getEmployeeSubordinates = createServerFn({ method: "GET" }).inputValidator(EmployeeIdSchema).handler(async ({ data }) => {
return getPeopleSoftApi().request({
url: `/v1/employee/${encodeURIComponent(data.employeeId)}/subordinates`,
method: "GET"
}).then((r) => r.data);
});
const getEmployeeManager = createServerFn({ method: "GET" }).inputValidator(EmployeeIdSchema).handler(async ({ data }) => {
return getPeopleSoftApi().request({
url: `/v1/employee/${encodeURIComponent(data.employeeId)}/manager`,
method: "GET"
}).then((r) => r.data);
});
const getEmployeeGeneralManager = createServerFn({ method: "GET" }).inputValidator(EmployeeIdSchema).handler(async ({ data }) => {
return getPeopleSoftApi().request({
url: `/v1/employee/${encodeURIComponent(data.employeeId)}/generalManager`,
method: "GET"
}).then((r) => r.data);
});
const getDepartments = createServerFn({ method: "GET" }).handler(async () => {
return getPeopleSoftApi().request({
url: `/v1/department/all`,
method: "GET"
}).then((r) => r.data);
});
const getDepartmentById = createServerFn({ method: "GET" }).inputValidator(DepartmentIdSchema).handler(async ({ data }) => {
return getPeopleSoftApi().request({
url: `/v1/department/${encodeURIComponent(data.departmentId)}`,
method: "GET"
}).then((r) => r.data);
});
const getDepartmentManager = createServerFn({ method: "GET" }).inputValidator(DepartmentIdSchema).handler(async ({ data }) => {
return getPeopleSoftApi().request({
url: `/v1/department/${encodeURIComponent(data.departmentId)}/manager`,
method: "GET"
}).then((r) => r.data);
});
const getDepartmentEmployees = createServerFn({ method: "GET" }).inputValidator(DepartmentIdSchema).handler(async ({ data }) => {
return getPeopleSoftApi().request({
url: `/v1/department/${encodeURIComponent(data.departmentId)}/employees`,
method: "GET"
}).then((r) => r.data);
});
const getCompanyGeneralManager = createServerFn({ method: "GET" }).inputValidator(CompanyCodeSchema).handler(async ({ data }) => {
return getPeopleSoftApi().request({
url: `/v1/company/${encodeURIComponent(data.companyCode)}/generalManager`,
method: "GET"
}).then((r) => r.data);
});
//#endregion
export { createApproval as C, withdrawApproval as D, resubmitApproval as E, cancelApproval as S, getApprovals as T, getPreviousEmployeeIds as _, getActiveEmployees as a, GetApprovalsSchema as b, getDepartmentEmployees as c, getEmployeeByEmployeeId as d, getEmployeeGeneralManager as f, getEmployees as g, getEmployeeSupervisor as h, SearchEmployeesSchema as i, getDepartmentManager as l, getEmployeeSubordinates as m, DepartmentIdSchema as n, getCompanyGeneralManager as o, getEmployeeManager as p, EmployeeIdSchema as r, getDepartmentById as s, CompanyCodeSchema as t, getDepartments as u, searchEmployees as v, getApproval as w, approveApproval as x, GetApprovalSchema as y };
//# sourceMappingURL=peoplesoft-RYzK8IDF.js.map