From 0310614509f485ebe0a072b51582abe2a9ee68bb Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Sat, 31 Dec 2022 22:41:19 +0100 Subject: [PATCH] Created the domain controller --- server/controller/domain.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 server/controller/domain.js diff --git a/server/controller/domain.js b/server/controller/domain.js new file mode 100644 index 0000000..a257df5 --- /dev/null +++ b/server/controller/domain.js @@ -0,0 +1,9 @@ +const Domain = require('../models/Domain'); + +const exists = async (domainName) => (await Domain.findOne({where: {domainName}})) !== null; + +module.exports.getDomains = async () => (await Domain.findAll()).map(domain => (domain.domainName)); + +module.exports.deleteDomain = async (domainName) => await exists(domainName) ? await Domain.destroy({where: {domainName}}) : null; + +module.exports.createDomain = async (domainName) => !await exists(domainName) ? await Domain.create({domainName}) : null; \ No newline at end of file