diff options
Diffstat (limited to 'lib/nonsap/db.ts')
| -rw-r--r-- | lib/nonsap/db.ts | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/lib/nonsap/db.ts b/lib/nonsap/db.ts new file mode 100644 index 00000000..2b3cbda3 --- /dev/null +++ b/lib/nonsap/db.ts @@ -0,0 +1,68 @@ +import { oracleKnex } from '@/lib/oracle-db/db'; +import { unstable_cache } from 'next/cache'; + +// Types +export interface ScreenEvcp { + SCR_ID: string; + SCR_URL: string; + SCRT_CHK_YN: string; // 'Y' | 'N' + DEL_YN: string; // 'Y' | 'N' +} + +export interface ScreenAuthEvcp { + SCR_ID: string; + ACSR_GB_CD: string; // 'U' | 'R' | 'D' | 'E' + ACSR_ID: string; + AUTH_CD_SEARCH: string; // 'Y' | 'N' + AUTH_CD_ADD: string; + AUTH_CD_DEL: string; + AUTH_CD_SAVE: string; + AUTH_CD_PRINT: string; + AUTH_CD_DOWN: string; + AUTH_CD_UP: string; + AUTH_CD_APPROVAL: string; + AUTH_CD_PREV: string; + AUTH_CD_NEXT: string; +} + +export interface RoleEvcp { + ROLE_ID: string; + ROLE_NM: string; +} + +export interface RoleRelEvcp { + ROLE_ID: string; + EMPNO: string; +} + +// Fetch functions with cache + +export const getAllScreens = unstable_cache( + async () => { + const result = await oracleKnex('CMCVW_SCR_EVCP') + .select('*'); + return result as ScreenEvcp[]; + }, + ['nonsap-all-screens'], + { revalidate: 60 } +); + +export const getAuthsByScreenId = unstable_cache( + async (scrId: string) => { + const result = await oracleKnex('CMCVW_SCR_AUTH_EVCP') + .where('SCR_ID', scrId); + return result as ScreenAuthEvcp[]; + }, + ['nonsap-auths-by-screen-id'], + { revalidate: 60 } +); + +export const getUserRoles = unstable_cache( + async (empNo: string) => { + const result = await oracleKnex('CMCVW_ROLE_REL_EVCP') + .where('EMPNO', empNo); + return result as RoleRelEvcp[]; + }, + ['nonsap-user-roles'], + { revalidate: 60 } +); |
