Skip to content

Commit

Permalink
Merge pull request #145 from Kpoke/fix/updates
Browse files Browse the repository at this point in the history
fixes
  • Loading branch information
Kpoke authored May 1, 2023
2 parents a01d9b9 + 29c2eef commit 3c626da
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 0 deletions.
3 changes: 3 additions & 0 deletions __tests__/integration/grower_account/grower_account.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('/grower_account', () => {
about: 'about',
image_url: 'https://www.himage.com',
image_rotation: 44,
show_in_map: true,
};

after(async () => {
Expand All @@ -46,6 +47,7 @@ describe('/grower_account', () => {
expect(typeof res.body.reference_id).eql('number');
expect(res.body.organizations.length).to.eql(0);
expect(res.body.images.length).to.eql(0);
expect(res.body.show_in_map).to.eql(false);

const res2 = await request(app)
.post(`/grower_accounts`)
Expand All @@ -59,6 +61,7 @@ describe('/grower_account', () => {
expect(typeof res2.body.reference_id).eql('number');
expect(res2.body.organizations.length).to.eql(0);
expect(res2.body.images.length).to.eql(0);
expect(res.body.show_in_map).to.eql(false);
});

it('should not error out if duplicate wallet is sent', async () => {
Expand Down
53 changes: 53 additions & 0 deletions database/migrations/20230501001217-add-token-to-capture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'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', '20230501001217-add-token-to-capture-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', '20230501001217-add-token-to-capture-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
};
53 changes: 53 additions & 0 deletions database/migrations/20230501001718-show-in-map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'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', '20230501001718-show-in-map-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', '20230501001718-show-in-map-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,2 @@
ALTER TABLE capture DROP COLUMN token_id;
ALTER TABLE capture DROP COLUMN token_issued;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE capture ADD COLUMN token_id uuid;
ALTER TABLE capture ADD COLUMN token_issued boolean;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE grower_account DROP COLUMN show_in_map;
1 change: 1 addition & 0 deletions database/migrations/sqls/20230501001718-show-in-map-up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE grower_account ADD COLUMN show_in_map boolean DEFAULT false;
1 change: 1 addition & 0 deletions server/handlers/growerAccountHandler/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ const growerAccountComponent = {
phone: { type: 'string' },
about: { type: 'string' },
lat: { type: 'number' },
show_in_map: { type: 'boolean' },
lon: { type: 'number' },
location: { type: 'string' },
image_url: { type: 'string' },
Expand Down
3 changes: 3 additions & 0 deletions server/handlers/growerAccountHandler/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const growerAccountGetQuerySchema = Joi.object({
id: Joi.string().uuid(),
wallet: Joi.string(),
bulk_pack_file_name: Joi.string(),
show_in_map: Joi.boolean(),
}).unknown(false);

const growerAccountPostQuerySchema = Joi.object({
Expand All @@ -25,6 +26,7 @@ const growerAccountPostQuerySchema = Joi.object({
image_rotation: Joi.number().integer(),
first_registration_at: Joi.date().iso().required(),
bulk_pack_file_name: Joi.string(),
show_in_map: Joi.boolean(),
}).unknown(false);

const growerAccountPatchQuerySchema = Joi.object({
Expand All @@ -39,6 +41,7 @@ const growerAccountPatchQuerySchema = Joi.object({
image_rotation: Joi.number().integer(),
status: Joi.string().valid('active', 'deleted'),
gender: Joi.string().valid('male', 'female', 'neutral'),
show_in_map: Joi.boolean(),
}).unknown(false);

const growerAccountIdQuerySchema = Joi.object({
Expand Down
2 changes: 2 additions & 0 deletions server/models/GrowerAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class GrowerAccount {
bulk_pack_file_name,
created_at,
updated_at,
show_in_map,
}) {
return Object.freeze({
id,
Expand All @@ -57,6 +58,7 @@ class GrowerAccount {
bulk_pack_file_name,
created_at,
updated_at,
show_in_map,
});
}

Expand Down
1 change: 1 addition & 0 deletions server/repositories/GrowerAccountRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class GrowerAccountRepository extends BaseRepository {
.select(
'grower_account.id',
'grower_account.reference_id',
'grower_account.show_in_map',
'grower_account.wallet',
'grower_account.person_id',
'grower_account.organization_id',
Expand Down

0 comments on commit 3c626da

Please sign in to comment.