@@ -66,9 +66,35 @@ module.exports = {
6666 if ( req . currentUser . isBlocked || req . currentUser . isRemoved ) {
6767 throw new Error ( noAuthorizationError ) ;
6868 }
69- organization . name = args . organizationInput . name ,
70- organization . description = args . organizationInput . description ,
71- organization . contactInfo = args . organizationInput . contactInfo ,
69+ organization . name = args . organizationInput . name ;
70+ organization . description = args . organizationInput . description ;
71+ organization . contactInfo = args . organizationInput . contactInfo ;
72+ await organization . save ( ) ;
73+ organization = await Organization . findOne ( ) . lean ( ) ;
74+ return {
75+ ...organization ,
76+ exists : true ,
77+ } ;
78+ } else {
79+ throw new Error ( adminAccessError ) ;
80+ }
81+ } catch ( err ) {
82+ console . log ( err ) ;
83+ throw err ;
84+ }
85+ } ,
86+
87+ toggleMaintenanceMode : async ( args , req ) => {
88+ if ( ! req . isAuth ) {
89+ throw new Error ( authenticationError ) ;
90+ }
91+ try {
92+ let organization = await Organization . findOne ( { } ) ;
93+ if ( req . currentUser . isAdmin && organization ) {
94+ if ( req . currentUser . isBlocked || req . currentUser . isRemoved ) {
95+ throw new Error ( noAuthorizationError ) ;
96+ }
97+ organization . isUnderMaintenance = ! organization . isUnderMaintenance ;
7298 await organization . save ( ) ;
7399 organization = await Organization . findOne ( ) . lean ( ) ;
74100 return {
@@ -174,7 +200,7 @@ module.exports = {
174200 if ( user . isFirstAdmin ) {
175201 throw new Error ( firstAdminDemoteError ) ;
176202 }
177- if ( ! user . isAdmin ) {
203+ if ( ! user . isAdmin ) {
178204 throw new Error ( noAdminError ) ;
179205 }
180206 user . isAdmin = false ;
0 commit comments