generated from Greenstand/treetracker-microservice-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
827 additions
and
30 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
earnings_id,worker_id,phone,currency,amount,payment_confirmation_id,payment_id | ||
f3056760-4c36-4cf7-b625-ed656d314794,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,2,jomzy jor jor,2021-10-10T00:00:00.000Z | ||
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,3,jomzy jor jor,2021-10-10T00:00:00.000Z | ||
61714d24-6131-4296-ae36-30a7199cc645,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,4,jomzy jor jor,2021-10-10T00:00:00.000Z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
earnings_id,worker_id,phone,currency,amount,payment_id,payment_system | ||
f3056760-4c36-4cf7-b625-ed656d314794,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,2,jomzy jor jor,2021-10-10T00:00:00.000Z | ||
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,3,jomzy jor jor,2021-10-10T00:00:00.000Z | ||
61714d24-6131-4296-ae36-30a7199cc645,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,4,jomzy jor jor,2021-10-10T00:00:00.000Z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
earnings_id,phone,currency,amount,payment_confirmation_id,payment_system | ||
f3056760-4c36-4cf7-b625-ed656d314794,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,2,jomzy jor jor,2021-10-10T00:00:00.000Z | ||
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,3,jomzy jor jor,2021-10-10T00:00:00.000Z | ||
61714d24-6131-4296-ae36-30a7199cc645,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,4,jomzy jor jor,2021-10-10T00:00:00.000Z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
earnings_id,worker_id,phone,currency,payment_confirmation_id,payment_system | ||
f3056760-4c36-4cf7-b625-ed656d314794,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,2,jomzy jor jor,2021-10-10T00:00:00.000Z | ||
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,3,jomzy jor jor,2021-10-10T00:00:00.000Z | ||
61714d24-6131-4296-ae36-30a7199cc645,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,4,jomzy jor jor,2021-10-10T00:00:00.000Z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
earnings_id,worker_id,phone,amount,payment_confirmation_id,payment_system | ||
f3056760-4c36-4cf7-b625-ed656d314794,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,2,jomzy jor jor,2021-10-10T00:00:00.000Z | ||
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,3,jomzy jor jor,2021-10-10T00:00:00.000Z | ||
61714d24-6131-4296-ae36-30a7199cc645,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,4,jomzy jor jor,2021-10-10T00:00:00.000Z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
worker_id,phone,currency,amount,payment_confirmation_id,payment_system | ||
f3056760-4c36-4cf7-b625-ed656d314794,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,2,jomzy jor jor,2021-10-10T00:00:00.000Z | ||
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,3,jomzy jor jor,2021-10-10T00:00:00.000Z | ||
61714d24-6131-4296-ae36-30a7199cc645,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,4,jomzy jor jor,2021-10-10T00:00:00.000Z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
earnings_id,worker_id,phone,currency,amount,payment_confirmation_id,payment_system,paid_at | ||
f3056760-4c36-4cf7-b625-ed6,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,2,jomzy jor jor,2021-10-10T00:00:00.000Z | ||
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,3,jomzy jor jor,2021-10-10T00:00:00.000Z | ||
61714d24-6131-4296-ae36-30a7199cc645,Not sure for now,USD,700,4,jomzy jor jor,2021-10-10T00:00:00.000Z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
earnings_id,worker_id,phone,currency,amount,payment_confirmation_id,payment_system,paid_at | ||
f3056760-4c36-4cf7-b625-ed656d314794,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,2,jomzy jor jor,2021-10-10T00:00:00.000Z | ||
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,3,jomzy jor jor,2021-10-10T00:00:00.000Z | ||
61714d24-6131-4296-ae36-30a7199cc645,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,4,jomzy jor jor,2021-10-10T00:00:00.000Z | ||
9c10e443-4e08-40d4-9b73-5a931886f896,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,4,jomzy jor jor,2021-10-10T00:00:00.000Z | ||
3ab96dfd-274a-4097-8e7d-942e58203784,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,4,jomzy jor jor,2021-10-10T00:00:00.000Z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
earnings_id,worker_id,phone,currency,amount,payment_confirmation_id,payment_system,paid_at | ||
f3056760-4c36-4cf7-b625-ed656d314794,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,2,jomzy jor jor,2021-10-10T00:00:00.000Z | ||
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,3,jomzy jor jor,2021-10-10T00:00:00.000Z | ||
61714d24-6131-4296-ae36-30a7199cc645,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,4,jomzy jor jor,2021-10-10T00:00:00.000Z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class GenericObject { | ||
constructor(payload) { | ||
this._object = payload; | ||
} | ||
|
||
delete_property(property) { | ||
delete this._object[property]; | ||
} | ||
|
||
change_property(property, value) { | ||
this._object[property] = value; | ||
} | ||
} | ||
|
||
module.exports = { | ||
GenericObject, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
const { v4: uuid } = require('uuid'); | ||
const sinon = require('sinon'); | ||
const knex = require('../server/database/knex'); | ||
const s3 = require('../server/services/s3'); | ||
|
||
const workerId = '71be6266-81fe-476f-a563-9bc1c61fc037'; | ||
const earningsPaymentObject = { | ||
worker_id: workerId, | ||
amount: 700, | ||
payment_confirmation_id: uuid(), | ||
payment_system: 'cash', | ||
currency: 'USD', | ||
status: 'calculated', | ||
paid_at: new Date().toISOString(), | ||
}; | ||
const earningsOne = { | ||
...earningsPaymentObject, | ||
payment_system: 'bike', | ||
id: '915b1c8c-e1d0-44f8-a6a7-7026e2a8f04b', | ||
}; | ||
const earningsTwo = { | ||
...earningsPaymentObject, | ||
id: 'f3056760-4c36-4cf7-b625-ed656d314794', | ||
}; | ||
const earningsThree = { | ||
...earningsPaymentObject, | ||
id: 'a69e5cec-945f-4693-8a94-01623ee44187', | ||
}; | ||
const earningsFour = { | ||
...earningsPaymentObject, | ||
id: '61714d24-6131-4296-ae36-30a7199cc645', | ||
}; | ||
const earningsWithPaidStatus = { | ||
...earningsPaymentObject, | ||
id: '9c10e443-4e08-40d4-9b73-5a931886f896', | ||
status: 'paid', | ||
}; | ||
const earningsWithCancelledStatus = { | ||
...earningsPaymentObject, | ||
id: '3ab96dfd-274a-4097-8e7d-942e58203784', | ||
status: 'cancelled', | ||
}; | ||
let stub; | ||
|
||
before(async () => { | ||
stub = sinon.stub(s3, 'putObject').returns({ promise: () => 'a' }); | ||
// prettier-ignore | ||
await knex.raw(` | ||
ALTER TABLE earnings ALTER COLUMN batch_id DROP NOT NULL; | ||
INSERT INTO stakeholder.stakeholder(id) | ||
VALUES ('${workerId}'); | ||
INSERT INTO public.earnings( | ||
id, worker_id, funder_id, amount, currency, calculated_at, consolidation_id, consolidation_period_start, consolidation_period_end, payment_confirmed_by, payment_confirmation_method, status, active) | ||
VALUES | ||
('${earningsOne.id}','${workerId}', '${uuid()}', '${earningsPaymentObject.amount}', '${earningsPaymentObject.currency}', now(), '${uuid()}', now(), now(), '${uuid()}','single', '${earningsOne.status}', true), | ||
('${earningsTwo.id}','${workerId}', '${uuid()}', '${earningsPaymentObject.amount}', '${earningsPaymentObject.currency}', now(), '${uuid()}', now(), now(), '${uuid()}','single', '${earningsTwo.status}', true), | ||
('${earningsThree.id}','${workerId}', '${uuid()}', '${earningsPaymentObject.amount}', '${earningsPaymentObject.currency}', now(), '${uuid()}', now(), now(), '${uuid()}','single', '${earningsThree.status}', true), | ||
('${earningsFour.id}','${workerId}', '${uuid()}', '${earningsPaymentObject.amount}', '${earningsPaymentObject.currency}', now(), '${uuid()}', now(), now(), '${uuid()}','batch', '${earningsFour.status}', true), | ||
('${earningsWithCancelledStatus.id}','${workerId}', '${uuid()}', '${earningsPaymentObject.amount}', '${earningsPaymentObject.currency}', now(), '${uuid()}', now(), now(), '${uuid()}','single', '${earningsWithCancelledStatus.status}', true), | ||
('${earningsWithPaidStatus.id}','${workerId}', '${uuid()}', '${earningsPaymentObject.amount}', '${earningsPaymentObject.currency}', now(), '${uuid()}', now(), now(), '${uuid()}','single', '${earningsWithPaidStatus.status}', true); | ||
`); | ||
}); | ||
|
||
after(async () => { | ||
stub.restore(); | ||
await knex.raw(` | ||
DELETE FROM public.earnings | ||
WHERE worker_id = '${workerId}'; | ||
DELETE FROM stakeholder.stakeholder | ||
WHERE id = '${workerId}'; | ||
ALTER TABLE earnings ALTER COLUMN batch_id SET NOT NULL; | ||
`); | ||
}); | ||
|
||
// should not be in the PATCH request body | ||
const { status, ...earnings } = earningsOne; | ||
const { status: status2, ...earningsPaid } = earningsWithPaidStatus; | ||
const { status: status3, ...earningsCancelled } = earningsWithCancelledStatus; | ||
|
||
module.exports = { | ||
earnings, | ||
earningsPaid, | ||
earningsCancelled, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
|
||
let dbm; | ||
let type; | ||
let seed; | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
let 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) { | ||
const filePath = path.join(__dirname, 'sqls', '20211010192212-createBatch-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) { | ||
const filePath = path.join(__dirname, 'sqls', '20211010192212-createBatch-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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
|
||
let dbm; | ||
let type; | ||
let seed; | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
let 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) { | ||
const filePath = path.join(__dirname, 'sqls', '20211010192838-createStakeholder-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) { | ||
const filePath = path.join(__dirname, 'sqls', '20211010192838-createStakeholder-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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE IF NOT EXISTS batch ( | ||
id uuid NOT NULL PRIMARY KEY, | ||
url varchar NOT NULL, | ||
status varchar NOT NULL, | ||
active boolean NOT NULL | ||
) |
1 change: 1 addition & 0 deletions
1
database/migrations/sqls/20211010192838-createStakeholder-down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/* Replace with your SQL commands */ |
4 changes: 4 additions & 0 deletions
4
database/migrations/sqls/20211010192838-createStakeholder-up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CREATE SCHEMA IF NOT EXISTS stakeholder; | ||
CREATE TABLE IF NOT EXISTS stakeholder.stakeholder( | ||
id uuid NOT NULL PRIMARY KEY | ||
) |
1 change: 1 addition & 0 deletions
1
...ls/20211005092140-createEarnings-down.sql → ...ls/20211010193244-createEarnings-down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...sqls/20211008100925-alterCapture-down.sql → ...sqls/20211010193339-alterCapture-down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/* Replace with your SQL commands */ | ||
ALTER TABLE treetracker.capture DROP earnings_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* Replace with your SQL commands */ | ||
CREATE SCHEMA IF NOT EXISTS treetracker; | ||
CREATE TABLE IF NOT EXISTS treetracker.capture ( | ||
id uuid NOT NULL PRIMARY KEY | ||
); | ||
ALTER TABLE treetracker.capture ADD earnings_id uuid REFERENCES public.earnings(id); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.