@rowengine/common 1.0.138 → 1.0.140

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,3 +14,4 @@ export * from './grade';
14
14
  export * from './inboundedit';
15
15
  export * from './weeds';
16
16
  export * from './refund';
17
+ export * from './transaction';
@@ -30,3 +30,4 @@ __exportStar(require("./grade"), exports);
30
30
  __exportStar(require("./inboundedit"), exports);
31
31
  __exportStar(require("./weeds"), exports);
32
32
  __exportStar(require("./refund"), exports);
33
+ __exportStar(require("./transaction"), exports);
@@ -0,0 +1,21 @@
1
+ import { Company } from './company';
2
+ export declare enum TransactionType {
3
+ CREDITS_BOUGHT = "CREDITS_BOUGHT",
4
+ CREDITS_DEBITED = "CREDITS_DEBITED",
5
+ PROJECT_REFUNDED = "PROJECT_REFUNDED"
6
+ }
7
+ export interface TransactionProject {
8
+ name: string;
9
+ area: number;
10
+ timeElapsedInSeconds: number;
11
+ timeOnQueueInSeconds: number;
12
+ createdAt: Date;
13
+ }
14
+ export interface Transaction {
15
+ company: Company;
16
+ userEmail: string;
17
+ currentBalance: number;
18
+ value: number;
19
+ type: TransactionType;
20
+ project?: TransactionProject;
21
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransactionType = void 0;
4
+ var TransactionType;
5
+ (function (TransactionType) {
6
+ TransactionType["CREDITS_BOUGHT"] = "CREDITS_BOUGHT";
7
+ TransactionType["CREDITS_DEBITED"] = "CREDITS_DEBITED";
8
+ TransactionType["PROJECT_REFUNDED"] = "PROJECT_REFUNDED";
9
+ })(TransactionType || (exports.TransactionType = TransactionType = {}));
@@ -5,3 +5,4 @@ export * from './project.model';
5
5
  export * from './refund.model';
6
6
  export * from './reload.model';
7
7
  export * from './user.model';
8
+ export * from './transaction.model';
@@ -21,3 +21,4 @@ __exportStar(require("./project.model"), exports);
21
21
  __exportStar(require("./refund.model"), exports);
22
22
  __exportStar(require("./reload.model"), exports);
23
23
  __exportStar(require("./user.model"), exports);
24
+ __exportStar(require("./transaction.model"), exports);
@@ -0,0 +1,23 @@
1
+ import mongoose from 'mongoose';
2
+ import { CompanyDoc } from './company.model';
3
+ import { TransactionType } from '../interfaces';
4
+ interface TransactionAttrs {
5
+ company: CompanyDoc;
6
+ userEmail: string;
7
+ project?: {
8
+ name: string;
9
+ area: number;
10
+ timeElapsedInSeconds: number;
11
+ timeOnQueueInSeconds: number;
12
+ createdAt: Date;
13
+ };
14
+ currentBalance: number;
15
+ value: number;
16
+ type: TransactionType;
17
+ }
18
+ type TransactionDoc = mongoose.Document & TransactionAttrs;
19
+ interface TransactionModel extends mongoose.Model<TransactionDoc> {
20
+ build(attrs: TransactionAttrs): TransactionDoc;
21
+ }
22
+ declare const TransactionModel: TransactionModel;
23
+ export { TransactionModel, TransactionDoc };
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TransactionModel = void 0;
7
+ const mongoose_1 = __importDefault(require("mongoose"));
8
+ const interfaces_1 = require("../interfaces");
9
+ const transactionSchema = new mongoose_1.default.Schema({
10
+ company: {
11
+ type: mongoose_1.default.Schema.Types.ObjectId,
12
+ ref: 'Company',
13
+ required: true,
14
+ },
15
+ userEmail: {
16
+ type: String,
17
+ required: true,
18
+ },
19
+ project: {
20
+ type: Object,
21
+ required: false,
22
+ },
23
+ currentBalance: {
24
+ type: Number,
25
+ required: true,
26
+ },
27
+ value: {
28
+ type: Number,
29
+ required: true,
30
+ },
31
+ type: {
32
+ type: String,
33
+ enum: Object.values(interfaces_1.TransactionType),
34
+ required: true,
35
+ },
36
+ }, {
37
+ toJSON: {
38
+ transform(doc, ret) {
39
+ ret.id = ret._id;
40
+ delete ret._id;
41
+ delete ret.__v;
42
+ },
43
+ },
44
+ });
45
+ const autoPopulate = function (next) {
46
+ // @ts-ignore
47
+ this.populate('company');
48
+ next();
49
+ };
50
+ transactionSchema.pre('findOne', autoPopulate);
51
+ transactionSchema.pre('find', autoPopulate);
52
+ // Pass the ts interface.
53
+ transactionSchema.statics.build = (attrs) => {
54
+ return new TransactionModel(attrs);
55
+ };
56
+ const TransactionModel = mongoose_1.default.model('Transaction', transactionSchema);
57
+ exports.TransactionModel = TransactionModel;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rowengine/common",
3
- "version": "1.0.138",
3
+ "version": "1.0.140",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "exports": {