From 756ad251d148fde343203f4e3287c67760a9fbd4 Mon Sep 17 00:00:00 2001
From: Jesus Arambula <61527697+JesusEArambula@users.noreply.github.com>
Date: Wed, 18 Aug 2021 17:29:39 -0700
Subject: [PATCH] Need help with server error 500
---
client/src/Resources/ResourceForm.js | 39 +++++++++++++++++++
client/src/Resources/ResourcesList.js | 20 ++++++----
.../20210819000753-create-city-state-zip.js | 27 +++++++++++++
models/resource.js | 3 ++
routes/api/resources.js | 34 +++++++++++++++-
5 files changed, 114 insertions(+), 9 deletions(-)
create mode 100644 migrations/20210819000753-create-city-state-zip.js
diff --git a/client/src/Resources/ResourceForm.js b/client/src/Resources/ResourceForm.js
index 8fbf7d7..4e6a18e 100644
--- a/client/src/Resources/ResourceForm.js
+++ b/client/src/Resources/ResourceForm.js
@@ -26,6 +26,9 @@ function ResourceForm() {
email: '',
website: '',
logo: '',
+ city: '',
+ state: '',
+ zip: '',
});
const [isUploading, setUploading] = useState(false);
@@ -173,6 +176,42 @@ function ResourceForm() {
/>
{error?.errorMessagesHTMLFor?.('address')}
+
>
)}
- {resource.name}
+ Name: {resource.name}
- {resource.orgtype}
+ Organization: {resource.orgtype}
- {resource.contactperson}
+ Contact Person: {resource.contactperson}
- {resource.address}
+ Address: {resource.address}
- {resource.phone}
+ City: {resource.city}
- {resource.email}
+ State: {resource.state}
- {resource.website}
+ ZIP Code: {resource.zip}
+
+ Phone Number: {resource.phone}
+
+ Email: {resource.email}
+
+ Website: {resource.website}
{user && (
diff --git a/migrations/20210819000753-create-city-state-zip.js b/migrations/20210819000753-create-city-state-zip.js
new file mode 100644
index 0000000..2f0c2f4
--- /dev/null
+++ b/migrations/20210819000753-create-city-state-zip.js
@@ -0,0 +1,27 @@
+'use strict';
+
+module.exports = {
+ up: async (queryInterface, Sequelize) => {
+ /**
+ * Add altering commands here.
+ *
+ * Example:
+ * await queryInterface.createTable('users', { id: Sequelize.INTEGER });
+ */
+ await queryInterface.addColumn('Resources', 'city', { type: Sequelize.STRING });
+ await queryInterface.addColumn('Resources', 'state', { type: Sequelize.STRING });
+ await queryInterface.addColumn('Resources', 'zip', { type: Sequelize.STRING });
+ },
+
+ down: async (queryInterface, Sequelize) => {
+ /**
+ * Add reverting commands here.
+ *
+ * Example:
+ * await queryInterface.dropTable('users');
+ */
+ await queryInterface.removeColumn('Resources', 'city');
+ await queryInterface.removeColumn('Resources', 'state');
+ await queryInterface.removeColumn('Resources', 'zip');
+ },
+};
diff --git a/models/resource.js b/models/resource.js
index 9422d4a..b5af4fa 100644
--- a/models/resource.js
+++ b/models/resource.js
@@ -30,6 +30,9 @@ module.exports = (sequelize, DataTypes) => {
email: DataTypes.STRING,
website: DataTypes.STRING,
address: DataTypes.TEXT,
+ city: DataTypes.STRING,
+ state: DataTypes.STRING,
+ zip: DataTypes.STRING,
},
{
sequelize,
diff --git a/routes/api/resources.js b/routes/api/resources.js
index ecb8b5d..af47244 100644
--- a/routes/api/resources.js
+++ b/routes/api/resources.js
@@ -26,7 +26,22 @@ router.get('/', async (req, res) => {
router.post('/', async (req, res) => {
try {
const record = await models.Resource.create(
- _.pick(req.body, ['name', 'logo', 'orgtype', 'contactperson', 'phone', 'address', 'lat', 'lng', 'email', 'website', 'CategoryId'])
+ _.pick(req.body, [
+ 'name',
+ 'logo',
+ 'orgtype',
+ 'contactperson',
+ 'phone',
+ 'address',
+ 'lat',
+ 'lng',
+ 'email',
+ 'website',
+ 'CategoryId',
+ 'city',
+ 'state',
+ 'zip',
+ ])
);
res.status(HttpStatus.CREATED).json(record.toJSON());
} catch (error) {
@@ -54,7 +69,22 @@ router.patch('/:id', async (req, res) => {
const record = await models.Resource.findByPk(req.params.id);
if (record) {
await record.update(
- _.pick(req.body, ['name', 'logo', 'orgtype', 'contactperson', 'phone', 'address', 'lat', 'lng', 'email', 'website', 'CategoryId'])
+ _.pick(req.body, [
+ 'name',
+ 'logo',
+ 'orgtype',
+ 'contactperson',
+ 'phone',
+ 'address',
+ 'lat',
+ 'lng',
+ 'email',
+ 'website',
+ 'CategoryId',
+ 'city',
+ 'state',
+ 'zip',
+ ])
);
res.json(record.toJSON());
} else {