From ccdcaf47be0f0242c6a9354a8ff8bacb9f80b536 Mon Sep 17 00:00:00 2001 From: Tibet Sprague Date: Thu, 28 Jul 2022 12:06:12 -0700 Subject: [PATCH] Allow for passing in geo_shape geoJSON when creating a group --- api/models/Group.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/api/models/Group.js b/api/models/Group.js index 24ea2b7af..f0ee4dabc 100644 --- a/api/models/Group.js +++ b/api/models/Group.js @@ -489,10 +489,10 @@ module.exports = bookshelf.Model.extend(merge({ throw Error("A group with that URL slug already exists") } - var attrs = defaults( + let attrs = defaults( pick(data, 'about_video_uri', 'accessibility', 'avatar_url', 'description', 'slug', 'category', - 'access_code', 'banner_url', 'location_id', 'location', 'group_data_type', 'moderator_descriptor', + 'access_code', 'banner_url', 'location_id', 'location', 'geo_shape', 'group_data_type', 'moderator_descriptor', 'moderator_descriptor_plural', 'name', 'type', 'type_descriptor', 'type_descriptor_plural', 'visibility' ), { @@ -507,6 +507,11 @@ module.exports = bookshelf.Model.extend(merge({ // eslint-disable-next-line camelcase const access_code = attrs.access_code || await Group.getNewAccessCode() + if (!isEmpty(attrs.geo_shape)) { + const st = knexPostgis(bookshelf.knex) + attrs.geo_shape = st.geomFromGeoJSON(attrs.geo_shape) + } + const group = new Group(merge(attrs, { access_code, created_at: new Date(),