Skip to content

Commit

Permalink
fix: update validation and table to allow null values
Browse files Browse the repository at this point in the history
  • Loading branch information
gwynndp committed Jun 16, 2022
1 parent 77961f6 commit f0a6374
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';

var dbm;
var type;
var seed;
var fs = require('fs');
var path = require('path');
var Promise;

/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function (options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
Promise = options.Promise;
};

exports.up = function (db) {
var filePath = path.join(
__dirname,
'sqls',
'20220613072449-update-capture-referenceid-allow-null-up.sql',
);
return new Promise(function (resolve, reject) {
fs.readFile(filePath, { encoding: 'utf-8' }, function (err, data) {
if (err) return reject(err);
console.log('received data: ' + data);

resolve(data);
});
}).then(function (data) {
return db.runSql(data);
});
};

exports.down = function (db) {
var filePath = path.join(
__dirname,
'sqls',
'20220613072449-update-capture-referenceid-allow-null-down.sql',
);
return new Promise(function (resolve, reject) {
fs.readFile(filePath, { encoding: 'utf-8' }, function (err, data) {
if (err) return reject(err);
console.log('received data: ' + data);

resolve(data);
});
}).then(function (data) {
return db.runSql(data);
});
};

exports._meta = {
version: 1,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE capture ALTER COLUMN reference_id NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE capture ALTER COLUMN reference_id NULL;
4 changes: 2 additions & 2 deletions server/handlers/captureHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const capturePostSchema = Joi.object({
image_url: Joi.string().uri().required(),
lat: Joi.number().required().min(-90).max(90).required(),
lon: Joi.number().required().min(-180).max(180).required(),
gps_accuracy: Joi.number().integer().required(),
gps_accuracy: Joi.number().integer().required().allow(null),
grower_account_id: Joi.string().uuid().required(),
planting_organization_id: Joi.string().uuid().required(),
planting_organization_id: Joi.string().uuid().allow(null).default(null),
device_configuration_id: Joi.string().uuid().required(),
reference_id: Joi.number().integer().default(null),
tree_id: Joi.string().uuid().default(null),
Expand Down
4 changes: 2 additions & 2 deletions server/handlers/tagHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ const {
const tagGetQuerySchema = Joi.object({
limit: Joi.number().integer().greater(0).less(101),
offset: Joi.number().integer().greater(-1),
owner_id: Joi.string(),
owner_id: Joi.string().default(null),
}).unknown(false);

const tagPostQuerySchema = Joi.object({
isPublic: Joi.boolean().required(),
name: Joi.string().required(),
owner_id: Joi.string().required(),
owner_id: Joi.string().allow(null).default(null),
}).unknown(false);

const TagPatchQuerySchema = Joi.object({
Expand Down

0 comments on commit f0a6374

Please sign in to comment.