11import {
2- addNewOrganization , deleteOrganizationById , updateOrganizationById , getOrganizations ,
3- } from "#services/organization" ;
4- import { logger } from "#util" ;
5-
6- async function addOrganization ( req , res ) {
7- const {
8- parent, startDate, name, accreditation,
9- } = req . body ;
10- try {
11- const organization = await addNewOrganization ( parent , startDate , name , accreditation , ) ;
12- res . json ( { res : `added organization${ organization . name } ` } ) ;
13- } catch ( error ) {
14- logger . error ( "Error while inserting" , error ) ;
15- res . status ( 500 ) ;
16- res . json ( { err : "Error while inserting in DB" } ) ;
17- }
2+ addNewOrganization , deleteOrganizationById , updateOrganizationById , getOrganizations ,
3+ } from "#services/organization" ;
4+ import { logger } from "#util" ;
5+
6+ async function addOrganization ( req , res ) {
7+ const {
8+ parent, startDate, name, accreditation,
9+ } = req . body ;
10+ try {
11+ const organization = await addNewOrganization ( parent , startDate , name , accreditation ) ;
12+ res . json ( { res : `added organization${ organization . name } ` } ) ;
13+ } catch ( error ) {
14+ logger . error ( "Error while inserting" , error ) ;
15+ res . status ( 500 ) ;
16+ res . json ( { err : "Error while inserting in DB" } ) ;
1817 }
19- async function deleteOrganization ( req , res ) {
20- const { organizationId } = req . params ;
21- try {
22- await deleteOrganizationById ( organizationId ) ;
23- res . json ( { res : "Organization deleted successfully" } ) ;
24- } catch ( error ) {
25- logger . error ( "Error while deleting" , error ) ;
26- res . status ( 500 ) ;
27- res . json ( { err : "Error while deleting from DB" } ) ;
28- }
18+ }
19+ async function deleteOrganization ( req , res ) {
20+ const { organizationId } = req . params ;
21+ try {
22+ await deleteOrganizationById ( organizationId ) ;
23+ res . json ( { res : "Organization deleted successfully" } ) ;
24+ } catch ( error ) {
25+ logger . error ( "Error while deleting" , error ) ;
26+ res . status ( 500 ) ;
27+ res . json ( { err : "Error while deleting from DB" } ) ;
2928 }
30-
31- async function updateOrganization ( req , res ) {
32- const {
33- id , ... data
34- } = req . body ;
35-
36- try {
37- await updateOrganizationById ( id , data ) ;
38- res . json ( { res : "organization updated" } ) ;
39- } catch ( error ) {
40- logger . error ( "Error while inserting" , error ) ;
41- res . status ( 500 ) ;
42- res . json ( { err : "Error while inserting in DB" } ) ;
43- }
29+ }
30+
31+ async function updateOrganization ( req , res ) {
32+ const {
33+ id , ... data
34+ } = req . body ;
35+
36+ try {
37+ await updateOrganizationById ( id , data ) ;
38+ res . json ( { res : "organization updated" } ) ;
39+ } catch ( error ) {
40+ logger . error ( "Error while inserting" , error ) ;
41+ res . status ( 500 ) ;
42+ res . json ( { err : "Error while inserting in DB" } ) ;
4443 }
45-
46- async function showOrganization ( req , res ) {
47- try {
48- const organization = await getOrganizations ( req . query ) ;
49- return res . json ( { res : organization } ) ;
50- } catch ( error ) {
51- logger . error ( "Error while fetching" , error ) ;
52- res . status ( 500 ) ;
53- return res . json ( { err : "Error while fetching the data" } ) ;
54- }
44+ }
45+
46+ async function showOrganization ( req , res ) {
47+ try {
48+ const organization = await getOrganizations ( req . query ) ;
49+ return res . json ( { res : organization } ) ;
50+ } catch ( error ) {
51+ logger . error ( "Error while fetching" , error ) ;
52+ res . status ( 500 ) ;
53+ return res . json ( { err : "Error while fetching the data" } ) ;
5554 }
56-
57- export default {
58- addOrganization , updateOrganization , deleteOrganization , showOrganization ,
59- } ;
60-
55+ }
56+
57+ export default {
58+ addOrganization , updateOrganization , deleteOrganization , showOrganization ,
59+ } ;
0 commit comments