Skip to content

Commit

Permalink
Build
Browse files Browse the repository at this point in the history
  • Loading branch information
TatianaFomina committed Nov 3, 2024
1 parent 26ab192 commit b84fce2
Show file tree
Hide file tree
Showing 45 changed files with 2,505 additions and 0 deletions.
118 changes: 118 additions & 0 deletions build/src/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DatabaseController = void 0;
var mongodb_1 = require("mongodb");
var errors_1 = require("./errors");
/**
* Database connection singleton
*/
var DatabaseController = /** @class */ (function () {
/**
* Creates controller instance
*
* @param connectionUri - mongo URI for connection
*/
function DatabaseController(connectionUri) {
if (!connectionUri) {
throw new errors_1.DatabaseError('Connection URI is not specified. Check .env');
}
this.connectionUri = connectionUri;
}
/**
* Connect to database
*/
DatabaseController.prototype.connect = function () {
return __awaiter(this, void 0, void 0, function () {
var _a, err_1;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
if (this.db) {
return [2 /*return*/, this.db];
}
_b.label = 1;
case 1:
_b.trys.push([1, 3, , 4]);
_a = this;
return [4 /*yield*/, mongodb_1.connect(this.connectionUri, {
useNewUrlParser: true,
useUnifiedTopology: true,
})];
case 2:
_a.connection = _b.sent();
this.db = this.connection.db();
return [2 /*return*/, this.db];
case 3:
err_1 = _b.sent();
throw new errors_1.DatabaseError(err_1);
case 4: return [2 /*return*/];
}
});
});
};
/**
* Close connection
*
* @returns {Promise<void>}
*/
DatabaseController.prototype.close = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
this.db = undefined;
if (!this.connection) {
return [2 /*return*/];
}
return [2 /*return*/, this.connection.close()];
});
});
};
/**
* Return MongoDB client
*
* @throws {DatabaseError} if the MongoDB client wasn't created by the `connect` method
*/
DatabaseController.prototype.getConnection = function () {
if (this.db == undefined) {
throw new errors_1.DatabaseError('You need to call the `connect` method before call `getConnection`');
}
return this.db;
};
return DatabaseController;
}());
exports.DatabaseController = DatabaseController;
27 changes: 27 additions & 0 deletions build/src/env-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";
/**
* @file import this file to test-files to provide env-vars for testing
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var dotenv = __importStar(require("dotenv"));
var path_1 = require("path");
Object.assign(process.env, dotenv.config({ path: path_1.resolve(__dirname, '../.env.test') }).parsed);
51 changes: 51 additions & 0 deletions build/src/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.AccountingServerError = exports.DatabaseError = exports.NonCriticalError = void 0;
var apollo_server_express_1 = require("apollo-server-express");
/**
* Class for non-critical errors (when the app works fine, but we need to send the error to the user, for example, auth-errors and others)
* Events inherited from this class won't be send to hawk
*/
var NonCriticalError = /** @class */ (function (_super) {
__extends(NonCriticalError, _super);
function NonCriticalError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return NonCriticalError;
}(apollo_server_express_1.ApolloError));
exports.NonCriticalError = NonCriticalError;
/**
* Class for critical database connection errors
*/
var DatabaseError = /** @class */ (function (_super) {
__extends(DatabaseError, _super);
function DatabaseError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return DatabaseError;
}(Error));
exports.DatabaseError = DatabaseError;
/**
* Class for critical server errors
*/
var AccountingServerError = /** @class */ (function (_super) {
__extends(AccountingServerError, _super);
function AccountingServerError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return AccountingServerError;
}(Error));
exports.AccountingServerError = AccountingServerError;
28 changes: 28 additions & 0 deletions build/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var server_1 = __importDefault(require("./server"));
var nodejs_1 = __importDefault(require("@hawk.so/nodejs"));
var dotenv_1 = __importDefault(require("dotenv"));
dotenv_1.default.config();
/**
* Enable HawkCatcher
*/
if (process.env.HAWK_CATCHER_TOKEN) {
nodejs_1.default.init(process.env.HAWK_CATCHER_TOKEN);
}
if (!process.env.PORT) {
console.error('Please, specify server port via .env PORT option');
process.exit(1);
}
if (!process.env.MONGO_ACCOUNTING_DATABASE_URI) {
console.error('Please, specify mongodb uri via .env MONGO_ACCOUNTING_DATABASE_URI option');
process.exit(1);
}
var server = new server_1.default(+process.env.PORT, process.env.PLAYGROUND_ENABLE === 'true', process.env.MONGO_ACCOUNTING_DATABASE_URI);
server.start().catch(function (err) {
nodejs_1.default.send(err);
console.log('Server runtime error' + err);
});
106 changes: 106 additions & 0 deletions build/src/models/account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Account = exports.AccountType = void 0;
var baseModel_1 = require("./baseModel");
var currency_1 = require("../types/currency");
var uuid_1 = require("uuid");
/**
* List of available account types
*/
var AccountType;
(function (AccountType) {
/**
* Credit account that represents debts before customers
*/
AccountType["Liability"] = "Liability";
/**
* Debit account, used as a cashbook
*/
AccountType["Asset"] = "Asset";
/**
* Credit account that represents company incomes
*/
AccountType["Revenue"] = "Revenue";
/**
* Debit account that represents company outcomes
*/
AccountType["Expense"] = "Expense";
})(AccountType = exports.AccountType || (exports.AccountType = {}));
/**
* The list of debit accounts
*/
var debitAccounts = [AccountType.Asset, AccountType.Expense];
/**
* The list of credit accounts
*/
var creditAccounts = [AccountType.Liability, AccountType.Revenue];
/**
* Account Model
*/
var Account = /** @class */ (function (_super) {
__extends(Account, _super);
/**
* @param data - account payload
*/
function Account(data) {
var _this = _super.call(this) || this;
/**
* Account identifier
*/
_this.id = '';
/**
* Account name
*/
_this.name = '';
/**
* Account type
*/
_this.type = AccountType.Liability;
/**
* Account currency
*/
_this.currency = currency_1.Currency.RUB;
/**
* Account creation time
*/
_this.dtCreated = 0;
if (!data.id) {
_this.id = uuid_1.v4();
}
else {
_this.id = data.id;
}
_this.name = data.name;
_this.type = data.type;
_this.currency = data.currency;
_this.dtCreated = data.dtCreated;
return _this;
}
/**
* Returns true if it is debit account
*/
Account.prototype.isDebit = function () {
return debitAccounts.indexOf(this.type) !== -1;
};
/**
* Returns true if it is credit account
*/
Account.prototype.isCredit = function () {
return creditAccounts.indexOf(this.type) !== -1;
};
return Account;
}(baseModel_1.BaseModel));
exports.Account = Account;
12 changes: 12 additions & 0 deletions build/src/models/baseModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseModel = void 0;
/**
* Abstract Base Model
*/
var BaseModel = /** @class */ (function () {
function BaseModel() {
}
return BaseModel;
}());
exports.BaseModel = BaseModel;
Loading

0 comments on commit b84fce2

Please sign in to comment.