@lomray/microservice-payment-stripe
Version:
Stripe payment microservice based on NodeJS & inverted json.
150 lines (146 loc) • 5.57 kB
JavaScript
;
var tslib = require('tslib');
var microserviceHelpers = require('@lomray/microservice-helpers');
var classTransformer = require('class-transformer');
var classValidator = require('class-validator');
var classValidatorJsonschema = require('class-validator-jsonschema');
var typeorm = require('typeorm');
var couponDuration = require('../constants/coupon-duration.js');
var promoCode = require('./promo-code.js');
var Coupon_1;
let Coupon = Coupon_1 = class Coupon {
/**
* Check if amountOff exists
*/
static isAmountOffExists(entity) {
return Boolean(entity.amountOff);
}
/**
* Check if duration is repeating
*/
static isDurationRepeating(entity) {
return entity.duration === couponDuration.REPEATING;
}
};
tslib.__decorate([
classValidatorJsonschema.JSONSchema({
description: 'Field for storing id of according coupon entity created on payment service side',
}),
typeorm.PrimaryColumn({ type: 'varchar', length: 8 }),
classValidator.Length(1, 8),
tslib.__metadata("design:type", String)
], Coupon.prototype, "couponId", void 0);
tslib.__decorate([
typeorm.Column({ type: 'uuid', default: null }),
microserviceHelpers.IsNullable(),
microserviceHelpers.IsUndefinable(),
classValidator.Length(1, 36),
tslib.__metadata("design:type", Object)
], Coupon.prototype, "userId", void 0);
tslib.__decorate([
classValidatorJsonschema.JSONSchema({
description: 'Name of the coupon displayed to customers on for instance invoices or receipts',
}),
typeorm.Column({ type: 'varchar', length: 100, default: null }),
microserviceHelpers.IsNullable(),
microserviceHelpers.IsUndefinable(),
classValidator.Length(1, 100),
tslib.__metadata("design:type", Object)
], Coupon.prototype, "name", void 0);
tslib.__decorate([
classValidatorJsonschema.JSONSchema({
description: 'Amount that will be taken off the subtotal of any invoices for this customer.',
}),
typeorm.Column({ type: 'float', default: null }),
microserviceHelpers.IsNullable(),
microserviceHelpers.IsUndefinable(),
classValidator.IsNumber(),
tslib.__metadata("design:type", Object)
], Coupon.prototype, "amountOff", void 0);
tslib.__decorate([
classValidatorJsonschema.JSONSchema({
description: 'Percent that will be taken off the subtotal of any invoices for this customer for the duration of the coupon.',
}),
typeorm.Column({ type: 'int', default: null }),
microserviceHelpers.IsNullable(),
microserviceHelpers.IsUndefinable(),
microserviceHelpers.IsValidate(Coupon_1, (entity) => !Coupon_1.isAmountOffExists(entity)),
classValidator.Min(1),
classValidator.Max(100),
classValidator.IsNumber(),
tslib.__metadata("design:type", Object)
], Coupon.prototype, "percentOff", void 0);
tslib.__decorate([
typeorm.Column({
type: 'enum',
enum: couponDuration,
}),
classValidator.IsEnum(couponDuration),
tslib.__metadata("design:type", String)
], Coupon.prototype, "duration", void 0);
tslib.__decorate([
classValidatorJsonschema.JSONSchema({
description: 'If duration is repeating, the number of months the coupon applies.',
}),
typeorm.Column({ type: 'int', default: null }),
microserviceHelpers.IsNullable(),
microserviceHelpers.IsUndefinable(),
microserviceHelpers.IsValidate(Coupon_1, (entity) => Coupon_1.isDurationRepeating(entity)),
classValidator.IsNumber(),
tslib.__metadata("design:type", Object)
], Coupon.prototype, "durationInMonths", void 0);
tslib.__decorate([
classValidatorJsonschema.JSONSchema({
description: 'Maximum number of times this coupon can be redeemed, in total, ' +
'across all customers, before it is no longer valid.',
}),
typeorm.Column({ type: 'int', default: null }),
microserviceHelpers.IsNullable(),
microserviceHelpers.IsUndefinable(),
classValidator.IsNumber(),
tslib.__metadata("design:type", Object)
], Coupon.prototype, "maxRedemptions", void 0);
tslib.__decorate([
microserviceHelpers.IsTypeormDate(),
typeorm.CreateDateColumn(),
tslib.__metadata("design:type", Date)
], Coupon.prototype, "createdAt", void 0);
tslib.__decorate([
microserviceHelpers.IsTypeormDate(),
typeorm.UpdateDateColumn(),
tslib.__metadata("design:type", Date)
], Coupon.prototype, "updatedAt", void 0);
tslib.__decorate([
classValidator.IsObject({ each: true }),
typeorm.ManyToMany('Product', 'coupons'),
typeorm.JoinTable({
name: 'coupon_products_product',
joinColumn: {
name: 'couponId',
referencedColumnName: 'couponId',
},
inverseJoinColumn: {
name: 'productId',
referencedColumnName: 'productId',
},
}),
tslib.__metadata("design:type", Array)
], Coupon.prototype, "products", void 0);
tslib.__decorate([
typeorm.OneToMany('PromoCode', 'coupon'),
classValidator.IsObject({ each: true }),
classTransformer.Type(() => promoCode),
classValidator.ValidateNested(),
tslib.__metadata("design:type", Array)
], Coupon.prototype, "promoCodes", void 0);
Coupon = Coupon_1 = tslib.__decorate([
classValidatorJsonschema.JSONSchema({
properties: {
products: { $ref: '#/definitions/Product', type: 'array' },
promoCodes: { $ref: '#/definitions/PromoCode', type: 'array' },
},
}),
typeorm.Entity()
], Coupon);
var CouponEntity = Coupon;
module.exports = CouponEntity;