Replaces MongoDB support with PostgreSQL (#151)

- All schemas have been rewritten to a relational model
- All services have been rewritten to accommodate the new data model
- Adds idempotency keys to core endpoints allowing you to retry requests with no additional side effects
- Adds staged jobs to avoid putting jobs in the queue when transactions abort
- Adds atomic transactions to all methods with access to the data layer

Co-authored-by: Oliver Windall Juhl <oliver@mrbltech.com>
This commit is contained in:
Sebastian Rindom
2021-01-26 10:26:14 +01:00
co-authored by Oliver Windall Juhl
parent 5f819486fc
commit f1baca3cbd
499 changed files with 25909 additions and 16128 deletions
+9 -13
View File
@@ -1,23 +1,19 @@
import mongoose from "mongoose"
String.prototype.equals = function(that) {
return this === that
}
import randomize from "randomatic";
class IdMap {
ids = {}
ids = {};
getId(key, backend=false) {
getId(key, prefix = "", length = 10) {
if (this.ids[key]) {
return this.ids[key]
return this.ids[key];
}
const mongooseId = `${mongoose.Types.ObjectId()}`
this.ids[key] = mongooseId
const id = `${prefix && prefix + "_"}${randomize("Aa0", length)}`;
this.ids[key] = id;
return mongooseId
return id;
}
}
const instance = new IdMap()
export default instance
const instance = new IdMap();
export default instance;
+3 -1
View File
@@ -1 +1,3 @@
export { default as IdMap } from "./id-map"
export { default as IdMap } from "./id-map";
export { default as MockRepository } from "./mock-repository";
export { default as MockManager } from "./mock-manager";
@@ -0,0 +1,13 @@
export default {
getCustomRepository: function (repo) {
return repo;
},
transaction: function (isolationOrCb, cb) {
if (typeof isolationOrCb === "string") {
return cb(this);
} else {
return isolationOrCb(this);
}
},
};
@@ -0,0 +1,67 @@
export default ({
create,
update,
remove,
softRemove,
find,
findOne,
findOneOrFail,
save,
} = {}) => {
return {
create: jest.fn().mockImplementation((...args) => {
if (create) {
return create(...args);
}
return {};
}),
softRemove: jest.fn().mockImplementation((...args) => {
if (softRemove) {
return softRemove(...args);
}
return {};
}),
remove: jest.fn().mockImplementation((...args) => {
if (remove) {
return remove(...args);
}
return {};
}),
update: jest.fn().mockImplementation((...args) => {
if (update) {
return update(...args);
}
}),
findOneOrFail: jest.fn().mockImplementation((...args) => {
if (findOneOrFail) {
return findOneOrFail(...args);
}
}),
findOne: jest.fn().mockImplementation((...args) => {
if (findOne) {
return findOne(...args);
}
}),
findOneOrFail: jest.fn().mockImplementation((...args) => {
if (findOneOrFail) {
return findOneOrFail(...args);
}
}),
find: jest.fn().mockImplementation((...args) => {
if (find) {
return find(...args);
}
}),
softRemove: jest.fn().mockImplementation((...args) => {
if (softRemove) {
return softRemove(...args);
}
}),
save: jest.fn().mockImplementation((...args) => {
if (save) {
return save(...args);
}
return Promise.resolve(...args);
}),
};
};