소스 검색

merge from update fitur sales

pearlgw 2 달 전
부모
커밋
59be8c2b6b
26개의 변경된 파일298개의 추가작업 그리고 230개의 파일을 삭제
  1. 1 1
      entrypoint.sh
  2. 2 2
      src/controllers/admin/CityController.js
  3. 2 2
      src/controllers/admin/ExecutivesHistoryController.js
  4. 2 2
      src/controllers/admin/VendorController.js
  5. 2 2
      src/controllers/admin/VendorHistoryController.js
  6. 2 2
      src/controllers/sales/ExecutivesHistoryController.js
  7. 2 2
      src/controllers/sales/VendorHistoryController.js
  8. 21 23
      src/repository/admin/HospitalRepository.js
  9. 20 23
      src/repository/sales/HospitalRepository.js
  10. 5 3
      src/services/admin/CityService.js
  11. 9 1
      src/services/admin/ExecutivesHistoryService.js
  12. 12 9
      src/services/admin/HospitalService.js
  13. 16 8
      src/services/admin/VendorHistoryService.js
  14. 10 8
      src/services/admin/VendorService.js
  15. 9 1
      src/services/sales/ExecutivesHistoryService.js
  16. 24 8
      src/services/sales/HospitalService.js
  17. 8 2
      src/services/sales/VendorHistoryService.js
  18. 23 0
      src/validators/admin/city/CityValidators.js
  19. 12 1
      src/validators/admin/executives_history/ExecutivesHistoriValidators.js
  20. 0 50
      src/validators/admin/hospital/HospitalValidators.js
  21. 41 41
      src/validators/admin/sales/SalesValidators.js
  22. 34 0
      src/validators/admin/vendor/VendorValidators.js
  23. 14 1
      src/validators/admin/vendor_history/VendorHistoriValidators.js
  24. 13 2
      src/validators/sales/executives_history/ExecutivesHistoriValidators.js
  25. 0 35
      src/validators/sales/vendor/VendorValidators.js
  26. 14 1
      src/validators/sales/vendor_history/VendorHistoriValidators.js

+ 1 - 1
entrypoint.sh

@@ -9,7 +9,7 @@ npx prisma migrate dev --name init
9 9
 # echo "♻️ Reset database dan menjalankan seeder..."
10 10
 # npx prisma migrate reset --force
11 11
 
12
-# echo "🌱 Menjalankan seeder (aman)..."
12
+echo "🌱 Menjalankan seeder (aman)..."
13 13
 # npx prisma db seed
14 14
 
15 15
 echo "🚀 Menjalankan aplikasi..."

+ 2 - 2
src/controllers/admin/CityController.js

@@ -3,7 +3,7 @@ const { CityResource } = require('../../resources/admin/city/CityResource.js');
3 3
 const cityService = require('../../services/admin/CityService.js');
4 4
 const { PaginationParam } = require('../../utils/PaginationParams.js');
5 5
 const { errorResponse, messageSuccessResponse } = require('../../utils/Response.js');
6
-const { validateStoreCityRequest } = require('../../validators/admin/city/CityValidators.js');
6
+const { validateStoreCityRequest, validateUpdateCityRequest } = require('../../validators/admin/city/CityValidators.js');
7 7
 
8 8
 exports.getAllCity = async (req, res) => {
9 9
     try {
@@ -42,7 +42,7 @@ exports.storeCity = async (req, res) => {
42 42
 exports.updateCity = async (req, res) => {
43 43
     try {
44 44
         const id = req.params.id;
45
-        const validatedData = validateStoreCityRequest(req.body);
45
+        const validatedData = validateUpdateCityRequest(req.body);
46 46
         await cityService.updateCityService(validatedData, id, req);
47 47
         return messageSuccessResponse(res, 'Success update city');
48 48
     } catch (err) {

+ 2 - 2
src/controllers/admin/ExecutivesHistoryController.js

@@ -3,7 +3,7 @@ const { ExecutivesHistoriResource } = require('../../resources/admin/executives_
3 3
 const executivesHistoryService = require('../../services/admin/ExecutivesHistoryService.js');
4 4
 const { PaginationParam } = require('../../utils/PaginationParams.js');
5 5
 const { errorResponse, messageSuccessResponse } = require('../../utils/Response.js');
6
-const { validateStoreExecutivesHistoryRequest } = require('../../validators/sales/executives_history/ExecutivesHistoriValidators.js');
6
+const { validateStoreExecutivesHistoryRequest, validateUpdateExecutivesHistoryRequest } = require('../../validators/admin/executives_history/ExecutivesHistoriValidators.js');
7 7
 
8 8
 exports.getAllExecutivesHistory = async (req, res) => {
9 9
     try {
@@ -40,7 +40,7 @@ exports.storeExecutivesHistory = async (req, res) => {
40 40
 
41 41
 exports.updateExecutivesHistory = async (req, res) => {
42 42
     try {
43
-        const validatedData = validateStoreExecutivesHistoryRequest(req.body);
43
+        const validatedData = validateUpdateExecutivesHistoryRequest(req.body);
44 44
         await executivesHistoryService.updateExecutivesHistoryService(validatedData, req);
45 45
         return messageSuccessResponse(res, 'Success update executives history');
46 46
     } catch (err) {

+ 2 - 2
src/controllers/admin/VendorController.js

@@ -3,7 +3,7 @@ const { VendorResource } = require('../../resources/admin/vendor/VendorResource.
3 3
 const vendorService = require('../../services/admin/VendorService.js');
4 4
 const { PaginationParam } = require('../../utils/PaginationParams.js');
5 5
 const { errorResponse, messageSuccessResponse } = require('../../utils/Response.js');
6
-const { validateStoreVendorRequest } = require('../../validators/sales/vendor/VendorValidators.js');
6
+const { validateStoreVendorRequest, validateUpdateVendorRequest } = require('../../validators/admin/vendor/VendorValidators.js');
7 7
 
8 8
 exports.getAllVendor = async (req, res) => {
9 9
     try {
@@ -42,7 +42,7 @@ exports.storeVendor = async (req, res) => {
42 42
 exports.updateVendor = async (req, res) => {
43 43
     try {
44 44
         const id = req.params.id;
45
-        const validatedData = validateStoreVendorRequest(req.body);
45
+        const validatedData = validateUpdateVendorRequest(req.body);
46 46
         await vendorService.updateVendorService(validatedData, id, req);
47 47
         return messageSuccessResponse(res, 'Success update vendor');
48 48
     } catch (err) {

+ 2 - 2
src/controllers/admin/VendorHistoryController.js

@@ -3,7 +3,7 @@ const { VendorHistoriResource } = require('../../resources/admin/vendor_history/
3 3
 const vendorHistoryService = require('../../services/admin/VendorHistoryService.js');
4 4
 const { PaginationParam } = require('../../utils/PaginationParams.js');
5 5
 const { errorResponse, messageSuccessResponse } = require('../../utils/Response.js');
6
-const { validateStoreVendorHistoryRequest } = require('../../validators/sales/vendor_history/VendorHistoriValidators.js');
6
+const { validateStoreVendorHistoryRequest, validateUpdateVendorHistoryRequest } = require('../../validators/admin/vendor_history/VendorHistoriValidators.js');
7 7
 
8 8
 exports.getAllVendorHistory = async (req, res) => {
9 9
     try {
@@ -41,7 +41,7 @@ exports.storeVendorHistory = async (req, res) => {
41 41
 
42 42
 exports.updateVendorHistory = async (req, res) => {
43 43
     try {
44
-        const validatedData = validateStoreVendorHistoryRequest(req.body);
44
+        const validatedData = validateUpdateVendorHistoryRequest(req.body);
45 45
         await vendorHistoryService.updateVendorHistoryService(validatedData, req);
46 46
         return messageSuccessResponse(res, 'Success update vendor history');
47 47
     } catch (err) {

+ 2 - 2
src/controllers/sales/ExecutivesHistoryController.js

@@ -3,7 +3,7 @@ const { ExecutivesHistoriCollection } = require('../../resources/sales/executive
3 3
 const executivesHistoryService = require('../../services/sales/ExecutivesHistoryService.js');
4 4
 const { PaginationParam } = require('../../utils/PaginationParams.js');
5 5
 const { errorResponse, messageSuccessResponse } = require('../../utils/Response.js');
6
-const { validateStoreExecutivesHistoryRequest } = require('../../validators/admin/executives_history/ExecutivesHistoriValidators.js');
6
+const { validateStoreExecutivesHistoryRequest, validateUpdateExecutivesHistoryRequest } = require('../../validators/sales/executives_history/ExecutivesHistoriValidators.js');
7 7
 
8 8
 exports.getAllExecutivesHistory = async (req, res) => {
9 9
     try {
@@ -40,7 +40,7 @@ exports.storeExecutivesHistory = async (req, res) => {
40 40
 
41 41
 exports.updateExecutivesHistory = async (req, res) => {
42 42
     try {
43
-        const validatedData = validateStoreExecutivesHistoryRequest(req.body);
43
+        const validatedData = validateUpdateExecutivesHistoryRequest(req.body);
44 44
         await executivesHistoryService.updateExecutivesHistoryService(validatedData, req);
45 45
         return messageSuccessResponse(res, 'Success update executives history');
46 46
     } catch (err) {

+ 2 - 2
src/controllers/sales/VendorHistoryController.js

@@ -3,7 +3,7 @@ const { VendorHistoriResource } = require('../../resources/sales/vendor_history/
3 3
 const vendorHistoryService = require('../../services/sales/VendorHistoryService.js');
4 4
 const { PaginationParam } = require('../../utils/PaginationParams.js');
5 5
 const { errorResponse, messageSuccessResponse } = require('../../utils/Response.js');
6
-const { validateStoreVendorHistoryRequest } = require('../../validators/admin/vendor_history/VendorHistoriValidators.js');
6
+const { validateStoreVendorHistoryRequest, validateUpdateVendorHistoryRequest } = require('../../validators/sales/vendor_history/VendorHistoriValidators.js');
7 7
 
8 8
 exports.getAllVendorHistory = async (req, res) => {
9 9
     try {
@@ -41,7 +41,7 @@ exports.storeVendorHistory = async (req, res) => {
41 41
 
42 42
 exports.updateVendorHistory = async (req, res) => {
43 43
     try {
44
-        const validatedData = validateStoreVendorHistoryRequest(req.body);
44
+        const validatedData = validateUpdateVendorHistoryRequest(req.body);
45 45
         await vendorHistoryService.updateVendorHistoryService(validatedData, req);
46 46
         return messageSuccessResponse(res, 'Success update vendor history');
47 47
     } catch (err) {

+ 21 - 23
src/repository/admin/HospitalRepository.js

@@ -101,32 +101,30 @@ const HospitalRepository = {
101 101
         return prisma.hospital.create({ data });
102 102
     },
103 103
 
104
+    // update: async (id, data) => {
105
+    //     return prisma.hospital.update({
106
+    //         where: { id },
107
+    //         data: {
108
+    //             name: data.name,
109
+    //             hospital_code: data.hospital_code,
110
+    //             type: data.type,
111
+    //             ownership: data.ownership,
112
+    //             province: { connect: { id: data.province_id } },
113
+    //             city: { connect: { id: data.city_id } },
114
+    //             address: data.address,
115
+    //             // simrs_type: data.simrs_type,
116
+    //             contact: data.contact,
117
+    //             note: data.note,
118
+    //             image: data.image,
119
+    //             progress_status: data.progress_status,
120
+    //         }
121
+    //     });
122
+    // },
123
+
104 124
     update: async (id, data) => {
105 125
         return prisma.hospital.update({
106 126
             where: { id },
107
-            data: {
108
-                name: data.name,
109
-                hospital_code: data.hospital_code,
110
-                type: data.type,
111
-                ownership: data.ownership,
112
-                // province: { connect: { id: data.province_id } },
113
-                // city: { connect: { id: data.city_id } },
114
-                ...(data.province_id && {
115
-                    province: { connect: { id: data.province_id } },
116
-                }),
117
-                ...(data.city_id && {
118
-                    city: { connect: { id: data.city_id } },
119
-                }),
120
-                address: data.address,
121
-                // simrs_type: data.simrs_type,
122
-                contact: data.contact,
123
-                note: data.note,
124
-                image: data.image,
125
-                gmaps_url: data.gmaps_url,
126
-                latitude: data.latitude,
127
-                longitude: data.longitude,
128
-                // progress_status: data.progress_status,
129
-            }
127
+            data
130 128
         });
131 129
     },
132 130
 };

+ 20 - 23
src/repository/sales/HospitalRepository.js

@@ -69,32 +69,29 @@ const HospitalRepository = {
69 69
         });
70 70
     },
71 71
 
72
+    // update: async (id, data) => {
73
+    //     return prisma.hospital.update({
74
+    //         where: { id },
75
+    //         data: {
76
+    //             name: data.name,
77
+    //             hospital_code: data.hospital_code,
78
+    //             type: data.type,
79
+    //             ownership: data.ownership,
80
+    //             province: { connect: { id: data.province_id } },
81
+    //             city: { connect: { id: data.city_id } },
82
+    //             address: data.address,
83
+    //             // simrs_type: data.simrs_type,
84
+    //             contact: data.contact,
85
+    //             note: data.note,
86
+    //             image: data.image,
87
+    //             progress_status: data.progress_status,
88
+    //         }
89
+    //     });
90
+    // },
72 91
     update: async (id, data) => {
73 92
         return prisma.hospital.update({
74 93
             where: { id },
75
-            data: {
76
-                name: data.name,
77
-                hospital_code: data.hospital_code,
78
-                type: data.type,
79
-                ownership: data.ownership,
80
-                // province: { connect: { id: data.province_id } },
81
-                // city: { connect: { id: data.city_id } },
82
-                ...(data.province_id && {
83
-                    province: { connect: { id: data.province_id } },
84
-                }),
85
-                ...(data.city_id && {
86
-                    city: { connect: { id: data.city_id } },
87
-                }),
88
-                address: data.address,
89
-                // simrs_type: data.simrs_type,
90
-                contact: data.contact,
91
-                note: data.note,
92
-                image: data.image,
93
-                gmaps_url: data.gmaps_url,
94
-                latitude: data.latitude,
95
-                longitude: data.longitude,
96
-                // progress_status: data.progress_status,
97
-            }
94
+            data
98 95
         });
99 96
     },
100 97
 };

+ 5 - 3
src/services/admin/CityService.js

@@ -53,9 +53,11 @@ exports.updateCityService = async (validateData, id, req) => {
53 53
         throw new HttpException("Data city not found", 404);
54 54
     }
55 55
 
56
-    const province = await ProvinceRepository.findById(validateData.province_id);
57
-    if (!province) {
58
-        throw new HttpException('Province not found', 404);
56
+    if (validateData.province_id) {
57
+        const province = await ProvinceRepository.findById(validateData.province_id);
58
+        if (!province) {
59
+            throw new HttpException('Province not found', 404);
60
+        }
59 61
     }
60 62
 
61 63
     const data = await CityRepository.update(id, validateData);

+ 9 - 1
src/services/admin/ExecutivesHistoryService.js

@@ -93,8 +93,16 @@ exports.updateExecutivesHistoryService = async (validateData, req) => {
93 93
         throw new HttpException("Executives history not found", 404);
94 94
     }
95 95
 
96
+    if (validateData.start_term && validateData.end_term) {
97
+        if (validateData.start_term >= validateData.end_term) {
98
+            throw new HttpException("End term must be after start_term", 400)
99
+        }
100
+    }
101
+
96 102
     const payload = {
97
-        ...validateData
103
+        ...validateData,
104
+        start_term: validateData.start_term ? new Date(validateData.start_term) : executivesHistory.start_term,
105
+        end_term: validateData.end_term ? new Date(validateData.end_term) : executivesHistory.end_term,
98 106
     };
99 107
 
100 108
     const data = await ExecutivesHistoryRepository.update(id_executives_history, payload);

+ 12 - 9
src/services/admin/HospitalService.js

@@ -122,14 +122,18 @@ exports.updateHospitalService = async (validateData, id, req) => {
122 122
         throw new HttpException("Hospital data not found", 404);
123 123
     }
124 124
 
125
-    const province = await ProvinceRepository.findById(validateData.province_id);
126
-    if (!province) {
127
-        throw new HttpException('Province not found', 404);
125
+    if (validateData.province_id) {
126
+        const province = await ProvinceRepository.findById(validateData.province_id);
127
+        if (!province) {
128
+            throw new HttpException('Province not found', 404);
129
+        }
128 130
     }
129 131
 
130
-    const city = await CityRepository.findById(validateData.city_id);
131
-    if (!city) {
132
-        throw new HttpException('City not found', 404);
132
+    if (validateData.city_id) {
133
+        const city = await CityRepository.findById(validateData.city_id);
134
+        if (!city) {
135
+            throw new HttpException('City not found', 404);
136
+        }
133 137
     }
134 138
 
135 139
     if (validateData.progress_status && !validProgressStatuses.includes(validateData.progress_status)) {
@@ -138,15 +142,14 @@ exports.updateHospitalService = async (validateData, id, req) => {
138 142
             422
139 143
         );
140 144
     }
145
+
141 146
     if (validateData.name && validateData.city_id) {
142 147
         const existingHospital = await prisma.hospital.findFirst({
143 148
             where: {
144 149
                 name: validateData.name,
145 150
                 city_id: validateData.city_id,
146 151
                 deletedAt: null,
147
-                // NOT: {
148
-                //     id: id
149
-                // }
152
+                NOT: { id }
150 153
             }
151 154
         });
152 155
 

+ 16 - 8
src/services/admin/VendorHistoryService.js

@@ -104,19 +104,27 @@ exports.updateVendorHistoryService = async (validateData, req) => {
104 104
         throw new HttpException("Vendor history not found", 404);
105 105
     }
106 106
 
107
-    await prisma.hospital.update({
108
-        where: { id: id_hospital },
109
-        data: {
110
-            simrs_type: validateData.simrs_type
111
-        }
112
-    });
107
+    if (validateData.simrs_type) {
108
+        await prisma.hospital.update({
109
+            where: { id: id_hospital },
110
+            data: {
111
+                simrs_type: validateData.simrs_type
112
+            },
113
+        });
114
+    }
113 115
 
116
+    if (validateData.contract_date && validateData.contract_expired_date) {
117
+        if (validateData.contract_date >= validateData.contract_expired_date) {
118
+            throw new HttpException("Contract expired date must be after contract date", 400)
119
+        }
120
+    }
121
+    
114 122
     const payload = {
115 123
         vendor_id: validateData.vendor_id,
116 124
         vendor_impression: validateData.vendor_impression,
117 125
         status: validateData.status,
118
-        contract_date: validateData.contract_date,
119
-        contract_expired_date: validateData.contract_expired_date
126
+        contract_date: validateData.contract_date ? new Date(validateData.contract_date) : vendor.contract_date,
127
+        contract_expired_date: validateData.contract_expired_date ? new Date(validateData.contract_expired_date) : vendor.contract_expired_date,
120 128
     };
121 129
 
122 130
     const data = await VendorHistoryRepository.update(id_vendor_history, payload);

+ 10 - 8
src/services/admin/VendorService.js

@@ -62,15 +62,17 @@ exports.updateVendorService = async (validateData, id, req) => {
62 62
         throw new HttpException("Data vendor not found", 404);
63 63
     }
64 64
 
65
-    const name_vendor = await prisma.vendor.findFirst({
66
-        where: {
67
-            name: validateData.name,
68
-            deletedAt: null
65
+    if (validateData.name && validateData.name !== vendor.name) {
66
+        const name_vendor = await prisma.vendor.findFirst({
67
+            where: {
68
+                name: validateData.name,
69
+                deletedAt: null
70
+            }
71
+        });
72
+
73
+        if (name_vendor) {
74
+            throw new HttpException("Vendor name must be unique", 400);
69 75
         }
70
-    });
71
-
72
-    if (name_vendor) {
73
-        throw new HttpException("Vendor name must be unique", 400);
74 76
     }
75 77
 
76 78
     const payload = {

+ 9 - 1
src/services/sales/ExecutivesHistoryService.js

@@ -92,8 +92,16 @@ exports.updateExecutivesHistoryService = async (validateData, req) => {
92 92
         throw new HttpException("Executives history not found", 404);
93 93
     }
94 94
 
95
+    if (validateData.start_term && validateData.end_term) {
96
+        if (validateData.start_term >= validateData.end_term) {
97
+            throw new HttpException("End term must be after start_term", 400)
98
+        }
99
+    }
100
+
95 101
     const payload = {
96
-        ...validateData
102
+        ...validateData,
103
+        start_term: validateData.start_term ? new Date(validateData.start_term) : executivesHistory.start_term,
104
+        end_term: validateData.end_term ? new Date(validateData.end_term) : executivesHistory.end_term,
97 105
     };
98 106
 
99 107
     const data = await ExecutivesHistoryRepository.update(id_executives_history, payload);

+ 24 - 8
src/services/sales/HospitalService.js

@@ -197,14 +197,18 @@ exports.updateHospitalService = async (validateData, id, req) => {
197 197
         throw new HttpException("You are not authorized to update hospital in this province", 403);
198 198
     }
199 199
 
200
-    const province = await ProvinceRepository.findById(validateData.province_id);
201
-    if (!province) {
202
-        throw new HttpException('Province not found', 404);
200
+    if (validateData.province_id) {
201
+        const province = await ProvinceRepository.findById(validateData.province_id);
202
+        if (!province) {
203
+            throw new HttpException('Province not found', 404);
204
+        }
203 205
     }
204 206
 
205
-    const city = await CityRepository.findById(validateData.city_id);
206
-    if (!city) {
207
-        throw new HttpException('City not found', 404);
207
+    if (validateData.city_id) {
208
+        const city = await CityRepository.findById(validateData.city_id);
209
+        if (!city) {
210
+            throw new HttpException('City not found', 404);
211
+        }
208 212
     }
209 213
 
210 214
     if (validateData.progress_status && !validProgressStatuses.includes(validateData.progress_status)) {
@@ -214,14 +218,20 @@ exports.updateHospitalService = async (validateData, id, req) => {
214 218
         );
215 219
     }
216 220
 
221
+<<<<<<< HEAD
217 222
     let existingHospital = null;
218 223
 
219 224
     if (validateData.name && validateData.city_id) {
220 225
         existingHospital = await prisma.hospital.findFirst({
226
+=======
227
+    if (validateData.name && validateData.city_id) {
228
+        const existingHospital = await prisma.hospital.findFirst({
229
+>>>>>>> update_fitur_sales
221 230
             where: {
222 231
                 name: validateData.name,
223 232
                 city_id: validateData.city_id,
224 233
                 deletedAt: null,
234
+<<<<<<< HEAD
225 235
                 // NOT: {
226 236
                 //     id: id,
227 237
                 // }
@@ -232,9 +242,15 @@ exports.updateHospitalService = async (validateData, id, req) => {
232 242
             throw new HttpException('Hospital with same name in this city already exists', 400);
233 243
         }
234 244
     }
245
+=======
246
+                NOT: { id }
247
+            }
248
+        });
249
+>>>>>>> update_fitur_sales
235 250
 
236
-    if (existingHospital) {
237
-        throw new HttpException('Hospital with same name in this city already exists', 400);
251
+        if (existingHospital) {
252
+            throw new HttpException('Hospital with same name in this city already exists', 400);
253
+        }
238 254
     }
239 255
 
240 256
     // Jika ada file baru, replace image

+ 8 - 2
src/services/sales/VendorHistoryService.js

@@ -111,12 +111,18 @@ exports.updateVendorHistoryService = async (validateData, req) => {
111 111
         }
112 112
     });
113 113
 
114
+    if (validateData.contract_date && validateData.contract_expired_date) {
115
+        if (validateData.contract_date >= validateData.contract_expired_date) {
116
+            throw new HttpException("Contract expired date must be after contract date", 400)
117
+        }
118
+    }
119
+
114 120
     const payload = {
115 121
         vendor_id: validateData.vendor_id,
116 122
         vendor_impression: validateData.vendor_impression,
117 123
         status: validateData.status,
118
-        contract_date: validateData.contract_date,
119
-        contract_expired_date: validateData.contract_expired_date
124
+        contract_date: validateData.contract_date ? new Date(validateData.contract_date) : vendor.contract_date,
125
+        contract_expired_date: validateData.contract_expired_date ? new Date(validateData.contract_expired_date) : vendor.contract_expired_date,
120 126
     };
121 127
 
122 128
     const data = await VendorHistoryRepository.update(id_vendor_history, payload);

+ 23 - 0
src/validators/admin/city/CityValidators.js

@@ -21,4 +21,27 @@ exports.validateStoreCityRequest = (body) => {
21 21
         name: name.trim(),
22 22
         province_id: province_id.trim()
23 23
     };
24
+};
25
+
26
+exports.validateUpdateCityRequest = (body) => {
27
+    const { name, province_id } = body;
28
+
29
+    // const errors = {};
30
+
31
+    // if (!name || name.trim() === '') {
32
+    //     errors.name = ['City name is required'];
33
+    // }
34
+
35
+    // if (!province_id || province_id.trim() === '') {
36
+    //     errors.province_id = ['Province ID is required'];
37
+    // }
38
+
39
+    // if (Object.keys(errors).length > 0) {
40
+    //     throw new HttpException(errors, 422);
41
+    // }
42
+
43
+    return {
44
+        name,
45
+        province_id
46
+    };
24 47
 };

+ 12 - 1
src/validators/admin/executives_history/ExecutivesHistoriValidators.js

@@ -74,4 +74,15 @@ exports.validateStoreExecutivesHistoryRequest = (body) => {
74 74
         start_term: start_term ? new Date(start_term) : null,
75 75
         end_term: end_term ? new Date(end_term) : null,
76 76
     };
77
-};
77
+};
78
+
79
+exports.validateUpdateExecutivesHistoryRequest = (body) => {
80
+    const { executive_name, contact, status, start_term, end_term } = body;
81
+    return {
82
+        executive_name,
83
+        contact,
84
+        status,
85
+        start_term,
86
+        end_term,
87
+    };
88
+}

+ 0 - 50
src/validators/admin/hospital/HospitalValidators.js

@@ -69,56 +69,6 @@ exports.validateStoreHospitalRequest = (body) => {
69 69
 exports.validateUpdateHospitalRequest = (body) => {
70 70
     const { name, hospital_code, type, ownership, province_id, city_id, address, contact, note, gmaps_url, latitude, longitude } = body;
71 71
 
72
-    // const errors = {};
73
-
74
-    // if (!name || name.trim() === '') {
75
-    //     errors.name = ['name is required'];
76
-    // }
77
-
78
-    // if (!hospital_code || hospital_code.trim() === '') {
79
-    //     errors.hospital_code = ['hospital code is required'];
80
-    // }
81
-
82
-    // if (!type || type.trim() === '') {
83
-    //     errors.type = ['type is required'];
84
-    // }
85
-
86
-    // if (!ownership || ownership.trim() === '') {
87
-    //     errors.ownership = ['ownership is required'];
88
-    // }
89
-
90
-    // if (!province_id || province_id.trim() === '') {
91
-    //     errors.province_id = ['province id is required'];
92
-    // }
93
-
94
-    // if (!city_id || city_id.trim() === '') {
95
-    //     errors.city_id = ['city id is required'];
96
-    // }
97
-
98
-    // if (!address || address.trim() === '') {
99
-    //     errors.address = ['address is required'];
100
-    // }
101
-
102
-    // if (!simrs_type || simrs_type.trim() === '') {
103
-    //     errors.simrs_type = ['simrs type is required'];
104
-    // }
105
-
106
-    // if (!progress_status || progress_status.trim() === '') {
107
-    //     errors.progress_status = ['progress status is required'];
108
-    // }
109
-
110
-    // if (!contact || contact.trim() === '') {
111
-    //     errors.contact = ['contact is required'];
112
-    // }
113
-
114
-    // if (!note || note.trim() === '') {
115
-    //     errors.note = ['note is required'];
116
-    // }
117
-
118
-    // if (Object.keys(errors).length > 0) {
119
-    //     throw new HttpException(errors, 422);
120
-    // }
121
-
122 72
     return {
123 73
         name,
124 74
         hospital_code,

+ 41 - 41
src/validators/admin/sales/SalesValidators.js

@@ -68,61 +68,61 @@ exports.validateCreateSalesRequest = (body) => {
68 68
 
69 69
 exports.validateUpdateSalesRequest = (body) => {
70 70
     const { email, firstname, lastname, password, province_ids } = body;
71
-    const errors = {};
71
+    // const errors = {};
72 72
 
73
-    if (!email || email.trim() === '') {
74
-        errors.email = ['Email is required'];
75
-    }
73
+    // if (!email || email.trim() === '') {
74
+    //     errors.email = ['Email is required'];
75
+    // }
76 76
 
77
-    if (!firstname || firstname.trim() === '') {
78
-        errors.firstname = ['First name is required'];
79
-    }
77
+    // if (!firstname || firstname.trim() === '') {
78
+    //     errors.firstname = ['First name is required'];
79
+    // }
80 80
 
81
-    if (!lastname || lastname.trim() === '') {
82
-        errors.lastname = ['Last name is required'];
83
-    }
81
+    // if (!lastname || lastname.trim() === '') {
82
+    //     errors.lastname = ['Last name is required'];
83
+    // }
84 84
 
85
-    if (!password || password.trim().length === 0) {
86
-        errors.password = ['Password is required'];
87
-    } else {
88
-        const trimmed = password.trim();
85
+    // if (!password || password.trim().length === 0) {
86
+    //     errors.password = ['Password is required'];
87
+    // } else {
88
+    //     const trimmed = password.trim();
89 89
 
90
-        const messages = [];
90
+    //     const messages = [];
91 91
 
92
-        if (trimmed.length < 8) {
93
-            messages.push('Password must be at least 8 characters');
94
-        }
92
+    //     if (trimmed.length < 8) {
93
+    //         messages.push('Password must be at least 8 characters');
94
+    //     }
95 95
 
96
-        if (!/[A-Z]/.test(trimmed)) {
97
-            messages.push('Password must contain uppercase letter');
98
-        }
96
+    //     if (!/[A-Z]/.test(trimmed)) {
97
+    //         messages.push('Password must contain uppercase letter');
98
+    //     }
99 99
 
100
-        if (!/[0-9]/.test(trimmed)) {
101
-            messages.push('Password must contain digit');
102
-        }
100
+    //     if (!/[0-9]/.test(trimmed)) {
101
+    //         messages.push('Password must contain digit');
102
+    //     }
103 103
 
104
-        if (!/[^a-zA-Z0-9]/.test(trimmed)) {
105
-            messages.push('Password must contain special character');
106
-        }
104
+    //     if (!/[^a-zA-Z0-9]/.test(trimmed)) {
105
+    //         messages.push('Password must contain special character');
106
+    //     }
107 107
 
108
-        if (messages.length > 0) {
109
-            errors.password = messages;
110
-        }
111
-    }
108
+    //     if (messages.length > 0) {
109
+    //         errors.password = messages;
110
+    //     }
111
+    // }
112 112
 
113
-    if (!Array.isArray(province_ids) || province_ids.length === 0) {
114
-        errors.province_ids = ['At least one province must be selected'];
115
-    }
113
+    // if (!Array.isArray(province_ids) || province_ids.length === 0) {
114
+    //     errors.province_ids = ['At least one province must be selected'];
115
+    // }
116 116
 
117
-    if (Object.keys(errors).length > 0) {
118
-        throw new HttpException(errors, 422);
119
-    }
117
+    // if (Object.keys(errors).length > 0) {
118
+    //     throw new HttpException(errors, 422);
119
+    // }
120 120
 
121 121
     return {
122
-        email: email.trim(),
123
-        firstname: firstname.trim(),
124
-        lastname: lastname.trim(),
125
-        password: password.trim(),
122
+        email,
123
+        firstname,
124
+        lastname,
125
+        password,
126 126
         province_ids
127 127
     };
128 128
 };

+ 34 - 0
src/validators/admin/vendor/VendorValidators.js

@@ -32,4 +32,38 @@ exports.validateStoreVendorRequest = (body) => {
32 32
         weaknesses: weaknesses.trim(),
33 33
         website: website.trim(),
34 34
     };
35
+};
36
+
37
+exports.validateUpdateVendorRequest = (body) => {
38
+    const { name, name_pt, strengths, weaknesses, website } = body;
39
+
40
+    // const errors = {};
41
+
42
+    // if (!name || name.trim() === '') {
43
+    //     errors.name = ['Vendor name is required'];
44
+    // }
45
+    // if (!name_pt || name_pt.trim() === '') {
46
+    //     errors.name_pt = ['Vendor name pt is required'];
47
+    // }
48
+    // if (!strengths || strengths.trim() === '') {
49
+    //     errors.strengths = ['Vendor strengths is required'];
50
+    // }
51
+    // if (!weaknesses || weaknesses.trim() === '') {
52
+    //     errors.weaknesses = ['Vendor weaknesses is required'];
53
+    // }
54
+    // if (!website || website.trim() === '') {
55
+    //     errors.website = ['Vendor website is required'];
56
+    // }
57
+
58
+    // if (Object.keys(errors).length > 0) {
59
+    //     throw new HttpException(errors, 422);
60
+    // }
61
+
62
+    return {
63
+        name,
64
+        name_pt,
65
+        strengths,
66
+        weaknesses,
67
+        website,
68
+    };
35 69
 };

+ 14 - 1
src/validators/admin/vendor_history/VendorHistoriValidators.js

@@ -70,4 +70,17 @@ exports.validateStoreVendorHistoryRequest = (body) => {
70 70
         contract_date: contract_date ? new Date(contract_date) : null,
71 71
         contract_expired_date: contract_expired_date ? new Date(contract_expired_date) : null,
72 72
     };
73
-};
73
+};
74
+
75
+exports.validateUpdateVendorHistoryRequest = (body) => {
76
+    const { simrs_type, vendor_id, vendor_impression, status, contract_date, contract_expired_date } = body;
77
+
78
+    return {
79
+        simrs_type,
80
+        vendor_id,
81
+        vendor_impression,
82
+        status,
83
+        contract_date,
84
+        contract_expired_date
85
+    };
86
+}

+ 13 - 2
src/validators/sales/executives_history/ExecutivesHistoriValidators.js

@@ -60,7 +60,7 @@ exports.validateStoreExecutivesHistoryRequest = (body) => {
60 60
         !errors.end_term &&
61 61
         new Date(end_term) <= new Date(start_term)
62 62
     ) {
63
-        errors.end_term = ['End term expired date must be after start term date'];
63
+        errors.end_term = ['End term date must be after start term date'];
64 64
     }
65 65
 
66 66
     if (Object.keys(errors).length > 0) {
@@ -74,4 +74,15 @@ exports.validateStoreExecutivesHistoryRequest = (body) => {
74 74
         start_term: start_term ? new Date(start_term) : null,
75 75
         end_term: end_term ? new Date(end_term) : null,
76 76
     };
77
-};
77
+};
78
+
79
+exports.validateUpdateExecutivesHistoryRequest = (body) => {
80
+    const { executive_name, contact, status, start_term, end_term } = body;
81
+    return {
82
+        executive_name,
83
+        contact,
84
+        status,
85
+        start_term,
86
+        end_term,
87
+    };
88
+}

+ 0 - 35
src/validators/sales/vendor/VendorValidators.js

@@ -1,35 +0,0 @@
1
-const HttpException = require('../../../utils/HttpException.js');
2
-
3
-exports.validateStoreVendorRequest = (body) => {
4
-    const { name, name_pt, strengths, weaknesses, website } = body;
5
-
6
-    const errors = {};
7
-
8
-    if (!name || name.trim() === '') {
9
-        errors.name = ['Vendor name is required'];
10
-    }
11
-    // if (!name_pt || name_pt.trim() === '') {
12
-    //     errors.name_pt = ['Vendor name pt is required'];
13
-    // }
14
-    // if (!strengths || strengths.trim() === '') {
15
-    //     errors.strengths = ['Vendor strengths is required'];
16
-    // }
17
-    // if (!weaknesses || weaknesses.trim() === '') {
18
-    //     errors.weaknesses = ['Vendor weaknesses is required'];
19
-    // }
20
-    // if (!website || website.trim() === '') {
21
-    //     errors.website = ['Vendor website is required'];
22
-    // }
23
-
24
-    if (Object.keys(errors).length > 0) {
25
-        throw new HttpException(errors, 422);
26
-    }
27
-
28
-    return {
29
-        name: name.trim(),
30
-        name_pt: name_pt.trim(),
31
-        strengths: strengths.trim(),
32
-        weaknesses: weaknesses.trim(),
33
-        website: website.trim(),
34
-    };
35
-};

+ 14 - 1
src/validators/sales/vendor_history/VendorHistoriValidators.js

@@ -70,4 +70,17 @@ exports.validateStoreVendorHistoryRequest = (body) => {
70 70
         contract_date: contract_date ? new Date(contract_date) : null,
71 71
         contract_expired_date: contract_expired_date ? new Date(contract_expired_date) : null,
72 72
     };
73
-};
73
+};
74
+
75
+exports.validateUpdateVendorHistoryRequest = (body) => {
76
+    const { simrs_type, vendor_id, vendor_impression, status, contract_date, contract_expired_date } = body;
77
+
78
+    return {
79
+        simrs_type,
80
+        vendor_id,
81
+        vendor_impression,
82
+        status,
83
+        contract_date,
84
+        contract_expired_date
85
+    };
86
+}