-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'backend_delete_form' into backend_create_form
- Loading branch information
Showing
5 changed files
with
201 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const data = require('../../../../backend/data/index'); | ||
const cookie = require('cookie'); | ||
|
||
|
||
module.exports = async (req, res) => { | ||
await data.initIfNotStarted(); | ||
|
||
if (req.method === 'DELETE') { | ||
// Get the Access Token from the request headers | ||
const token = cookie.parse(req.headers.cookie).token; | ||
const authStatus = await data.auth.checkAnyAdminUser(token, res); | ||
|
||
if (authStatus) { | ||
res.setHeader('Content-Type', 'application/json'); | ||
|
||
if (!req.query.name) { | ||
res.statusCode = 400; | ||
res.end( | ||
JSON.stringify( | ||
await data.util.resWrapper(async () => { | ||
throw Error('name URL param must be specified.'); | ||
}) | ||
) | ||
); | ||
return; | ||
} | ||
|
||
res.statusCode = 200; | ||
|
||
res.end( | ||
JSON.stringify( | ||
await data.util.resWrapper(async () => { | ||
return await data.forms.deleteForm( | ||
req.query.name, | ||
res | ||
); | ||
}) | ||
) | ||
); | ||
} | ||
} else { | ||
res.statusCode = 404; | ||
res.end(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.