|
1 | 1 | import { gql } from "graphql-request"; |
2 | 2 | import { gqlClient } from "./graphql-client"; |
3 | | -import type { Form, Application, SubmitInput } from "@/types/application"; |
4 | | - |
5 | | -const FORM_QUERY = gql` |
6 | | - query Form($id: ID!) { |
7 | | - form(id: $id) { |
8 | | - id title description recruitmentId type isActive createdBy createdAt updatedAt |
9 | | - questions { id label type options required sortOrder } |
| 3 | +import type { |
| 4 | + FormTemplate, |
| 5 | + MyApplication, |
| 6 | + RecruitmentPeriod, |
| 7 | + ApplicationSubmission, |
| 8 | + ApplicationListItem, |
| 9 | +} from "@/types/application"; |
| 10 | +import type { PagedResponse } from "@/types/common"; |
| 11 | + |
| 12 | +const MY_APPLICATION_QUERY = gql` |
| 13 | + query MyApplication { |
| 14 | + myApplication { |
| 15 | + id status formTemplateId track submittedAt |
| 16 | + answers { questionId value } |
| 17 | + paymentInfo { bank account amount holder } |
10 | 18 | } |
11 | 19 | } |
12 | 20 | `; |
13 | 21 |
|
14 | | -const FORMS_QUERY = gql` |
15 | | - query Forms($recruitmentId: String!) { |
16 | | - forms(recruitmentId: $recruitmentId) { |
17 | | - id title description recruitmentId type isActive createdBy createdAt updatedAt |
18 | | - questions { id label type options required sortOrder } |
| 22 | +const FORM_TEMPLATE_QUERY = gql` |
| 23 | + query FormTemplate($type: String!) { |
| 24 | + formTemplate(type: $type) { |
| 25 | + id type updatedAt |
| 26 | + questions { id type label required options order } |
19 | 27 | } |
20 | 28 | } |
21 | 29 | `; |
22 | 30 |
|
23 | | -const MY_APPLICATIONS_QUERY = gql` |
24 | | - query MyApplications { |
25 | | - myApplications { |
26 | | - id formId memberId status submittedAt approvedAt approvedBy updatedAt |
27 | | - answers { id questionId value } |
| 31 | +const RECRUITMENT_PERIOD_QUERY = gql` |
| 32 | + query RecruitmentPeriod($type: String!) { |
| 33 | + recruitmentPeriod(type: $type) { |
| 34 | + id type startDate endDate isActive |
28 | 35 | } |
29 | 36 | } |
30 | 37 | `; |
31 | 38 |
|
32 | | -const APPLICATIONS_QUERY = gql` |
33 | | - query Applications($formId: String!) { |
34 | | - applications(formId: $formId) { |
35 | | - id formId memberId status submittedAt approvedAt approvedBy updatedAt |
36 | | - answers { id questionId value } |
37 | | - } |
| 39 | +const SUBMIT_APPLICATION = gql` |
| 40 | + mutation SubmitApplication($input: ApplicationSubmissionInput!) { |
| 41 | + submitApplication(input: $input) { id status } |
38 | 42 | } |
39 | 43 | `; |
40 | 44 |
|
41 | | -const APPLICATION_QUERY = gql` |
42 | | - query Application($id: ID!) { |
43 | | - application(id: $id) { |
44 | | - id formId memberId status submittedAt approvedAt approvedBy updatedAt |
45 | | - answers { id questionId value } |
46 | | - } |
| 45 | +const CANCEL_APPLICATION = gql` |
| 46 | + mutation CancelApplication($id: ID!) { |
| 47 | + cancelApplication(id: $id) { id status } |
47 | 48 | } |
48 | 49 | `; |
49 | 50 |
|
50 | | -const SUBMIT_APPLICATION = gql` |
51 | | - mutation SubmitApplication($input: SubmitInput!) { |
52 | | - submitApplication(input: $input) { |
53 | | - id formId status submittedAt |
| 51 | +const APPLICATIONS_QUERY = gql` |
| 52 | + query Applications($filter: ApplicationFilterInput) { |
| 53 | + applications(filter: $filter) { |
| 54 | + items { id applicantName applicantEmail track status submittedAt } |
| 55 | + total page size |
54 | 56 | } |
55 | 57 | } |
56 | 58 | `; |
57 | 59 |
|
58 | | -const APPROVE_APPLICATIONS = gql` |
59 | | - mutation ApproveApplications($ids: [ID!]!) { |
60 | | - approveApplications(ids: $ids) { |
61 | | - id status approvedAt |
62 | | - } |
| 60 | +const APPROVE_APPLICATION = gql` |
| 61 | + mutation ApproveApplication($id: ID!) { |
| 62 | + approveApplication(id: $id) { id status } |
63 | 63 | } |
64 | 64 | `; |
65 | 65 |
|
66 | | -const CANCEL_APPLICATION = gql` |
67 | | - mutation CancelApplication($id: ID!) { |
68 | | - cancelApplication(id: $id) { |
69 | | - id status |
70 | | - } |
| 66 | +const BATCH_APPROVE = gql` |
| 67 | + mutation BatchApproveApplications($ids: [ID!]!) { |
| 68 | + batchApproveApplications(ids: $ids) { count } |
71 | 69 | } |
72 | 70 | `; |
73 | 71 |
|
74 | | -export async function getForm(id: string): Promise<Form> { |
75 | | - const data = await gqlClient.request<{ form: Form }>(FORM_QUERY, { id }); |
76 | | - return data.form; |
| 72 | +export async function getMyApplication(): Promise<MyApplication | null> { |
| 73 | + const data = await gqlClient.request<{ myApplication: MyApplication | null }>( |
| 74 | + MY_APPLICATION_QUERY, |
| 75 | + ); |
| 76 | + return data.myApplication; |
77 | 77 | } |
78 | 78 |
|
79 | | -export async function getForms(recruitmentId: string): Promise<Form[]> { |
80 | | - const data = await gqlClient.request<{ forms: Form[] }>(FORMS_QUERY, { recruitmentId }); |
81 | | - return data.forms; |
| 79 | +export async function getFormTemplate(type: string): Promise<FormTemplate> { |
| 80 | + const data = await gqlClient.request<{ formTemplate: FormTemplate }>( |
| 81 | + FORM_TEMPLATE_QUERY, |
| 82 | + { type }, |
| 83 | + ); |
| 84 | + return data.formTemplate; |
82 | 85 | } |
83 | 86 |
|
84 | | -export async function getMyApplications(): Promise<Application[]> { |
85 | | - const data = await gqlClient.request<{ myApplications: Application[] }>(MY_APPLICATIONS_QUERY); |
86 | | - return data.myApplications; |
| 87 | +export async function getRecruitmentPeriod(type: string): Promise<RecruitmentPeriod | null> { |
| 88 | + const data = await gqlClient.request<{ recruitmentPeriod: RecruitmentPeriod | null }>( |
| 89 | + RECRUITMENT_PERIOD_QUERY, |
| 90 | + { type }, |
| 91 | + ); |
| 92 | + return data.recruitmentPeriod; |
87 | 93 | } |
88 | 94 |
|
89 | | -export async function getApplications(formId: string): Promise<Application[]> { |
90 | | - const data = await gqlClient.request<{ applications: Application[] }>(APPLICATIONS_QUERY, { formId }); |
91 | | - return data.applications; |
| 95 | +export async function submitApplication(input: ApplicationSubmission): Promise<MyApplication> { |
| 96 | + const data = await gqlClient.request<{ submitApplication: MyApplication }>( |
| 97 | + SUBMIT_APPLICATION, |
| 98 | + { input }, |
| 99 | + ); |
| 100 | + return data.submitApplication; |
92 | 101 | } |
93 | 102 |
|
94 | | -export async function getApplication(id: string): Promise<Application> { |
95 | | - const data = await gqlClient.request<{ application: Application }>(APPLICATION_QUERY, { id }); |
96 | | - return data.application; |
| 103 | +export async function cancelApplication(id: string): Promise<MyApplication> { |
| 104 | + const data = await gqlClient.request<{ cancelApplication: MyApplication }>( |
| 105 | + CANCEL_APPLICATION, |
| 106 | + { id }, |
| 107 | + ); |
| 108 | + return data.cancelApplication; |
97 | 109 | } |
98 | 110 |
|
99 | | -export async function submitApplication(input: SubmitInput): Promise<Application> { |
100 | | - const data = await gqlClient.request<{ submitApplication: Application }>(SUBMIT_APPLICATION, { input }); |
101 | | - return data.submitApplication; |
| 111 | +export async function getApplications( |
| 112 | + filter: Record<string, unknown>, |
| 113 | +): Promise<PagedResponse<ApplicationListItem>> { |
| 114 | + const data = await gqlClient.request<{ applications: PagedResponse<ApplicationListItem> }>( |
| 115 | + APPLICATIONS_QUERY, |
| 116 | + { filter }, |
| 117 | + ); |
| 118 | + return data.applications; |
102 | 119 | } |
103 | 120 |
|
104 | | -export async function approveApplications(ids: string[]): Promise<Application[]> { |
105 | | - const data = await gqlClient.request<{ approveApplications: Application[] }>(APPROVE_APPLICATIONS, { ids }); |
106 | | - return data.approveApplications; |
| 121 | +export async function approveApplication(id: string): Promise<MyApplication> { |
| 122 | + const data = await gqlClient.request<{ approveApplication: MyApplication }>( |
| 123 | + APPROVE_APPLICATION, |
| 124 | + { id }, |
| 125 | + ); |
| 126 | + return data.approveApplication; |
107 | 127 | } |
108 | 128 |
|
109 | | -export async function cancelApplication(id: string): Promise<Application> { |
110 | | - const data = await gqlClient.request<{ cancelApplication: Application }>(CANCEL_APPLICATION, { id }); |
111 | | - return data.cancelApplication; |
| 129 | +export async function batchApproveApplications(ids: string[]): Promise<{ count: number }> { |
| 130 | + const data = await gqlClient.request<{ batchApproveApplications: { count: number } }>( |
| 131 | + BATCH_APPROVE, |
| 132 | + { ids }, |
| 133 | + ); |
| 134 | + return data.batchApproveApplications; |
112 | 135 | } |
0 commit comments