diff --git a/src/controllers/organization.controller.js b/src/controllers/organization.controller.js index df0c3e1b..b16a8fc8 100644 --- a/src/controllers/organization.controller.js +++ b/src/controllers/organization.controller.js @@ -4,6 +4,7 @@ import { assertHomeOrgExists, assertWalletIsSynced, assertDataLayerAvailable, + assertWalletIsAvailable, assertIfReadOnlyMode, } from '../utils/data-assertions'; @@ -11,10 +12,43 @@ export const findAll = async (req, res) => { return res.json(await Organization.getOrgsMap()); }; +export const createV2 = async (req, res) => { + try { + await assertIfReadOnlyMode(); + await assertDataLayerAvailable(); + await assertWalletIsAvailable(); + await assertWalletIsSynced(); + + const myOrganization = await Organization.getHomeOrg(); + + if (!myOrganization) { + return res.json({ + message: 'Your organization already exists.', + orgId: myOrganization.orgUid, + }); + } else { + const { name } = req.body; + const buffer = req.files.svg.data; + const svgIcon = buffer.toString('utf8'); + + return res.json({ + message: 'New organization created successfully.', + orgId: await Organization.createHomeOrganization(name, svgIcon, 'v1'), + }); + } + } catch (error) { + res.status(400).json({ + message: 'Error initiating your organization', + error: error.message, + }); + } +}; + export const create = async (req, res) => { try { await assertIfReadOnlyMode(); await assertDataLayerAvailable(); + await assertWalletIsAvailable(); await assertWalletIsSynced(); const myOrganization = await Organization.getHomeOrg(); diff --git a/src/routes/v1/resources/organization.js b/src/routes/v1/resources/organization.js index 3da03c91..f51e6c16 100644 --- a/src/routes/v1/resources/organization.js +++ b/src/routes/v1/resources/organization.js @@ -21,6 +21,10 @@ OrganizationRouter.post( }, ); +OrganizationRouter.post('/create', (req, res) => { + return OrganizationController.createV2(req, res); +}); + OrganizationRouter.put('/', (req, res) => { return OrganizationController.importOrg(req, res); });