Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(subscription-service): add ability to custom plan configuration #32

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';

var dbm;
var type;
var seed;
var fs = require('fs');
var path = require('path');
var 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) {
var filePath = path.join(
__dirname,
'sqls',
'20240711124515-add-features-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) {
var filePath = path.join(
__dirname,
'sqls',
'20240711124515-add-features-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,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';

var dbm;
var type;
var seed;
var fs = require('fs');
var path = require('path');
var 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) {
var filePath = path.join(
__dirname,
'sqls',
'20240711130845-add-plan-details-column.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) {
var filePath = path.join(
__dirname,
'sqls',
'20240711130845-add-plan-details-column.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,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';

var dbm;
var type;
var seed;
var fs = require('fs');
var path = require('path');
var 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) {
var filePath = path.join(
__dirname,
'sqls',
'20240715100807-seed-features-and-services-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) {
var filePath = path.join(
__dirname,
'sqls',
'20240715100807-seed-features-and-services-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,
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,50 @@ INSERT INTO main."plans"("name", created_on, created_by, description, price, cur
WHERE
cycle_name = 'MONTHLY'), 1);

INSERT INTO main.plan_items(created_on, created_by, "name", plan_item_type, plan_id, value)
VALUES (CURRENT_TIMESTAMP, '123e4567-e89b-12d3-a456-426614174002', 'Database', 'database',(
SELECT
id
FROM
main."plans" pl
WHERE
pl.name = 'Standard'), '{"name": "RDS_POSTGRES_STORAGE", "value": 50}');
INSERT INTO main.plan_items (created_on, created_by, "name", plan_item_type, plan_id, value)
VALUES (
CURRENT_TIMESTAMP,
'123e4567-e89b-12d3-a456-426614174002',
'Database',
'database',
(
SELECT id
FROM main.plans pl
WHERE pl.name = 'Premium'
),
'{
"service": {
"features": [
{ "name": "video call", "enabled": true, "description": "High quality video calling", "maxParticipants": 100 }
]
}
}'
);

INSERT INTO main.plan_items (created_on, created_by, "name", plan_item_type, plan_id, value)
VALUES (
CURRENT_TIMESTAMP,
'123e4567-e89b-12d3-a456-426614174002',
'Database',
'database',
(
SELECT id
FROM main.plans pl
WHERE pl.name = 'Premium'
),
'{
"service": {
"features": [
{ "name": "video call", "enabled": true, "description": "High quality video calling", "maxParticipants": 100 },
{ "name": "chat", "enabled": true, "description": "Real-time text chat", "property4": "value" },
{ "name": "recording", "enabled": false, "description": "Record meetings", "priority": 3, "storageLimit": "5GB" }
]
}
}'
);





INSERT INTO main.plan_items(created_on, created_by, "name", plan_item_type, plan_id, value)
VALUES (CURRENT_TIMESTAMP, '123e4567-e89b-12d3-a456-426614174002', 'Database', 'database',(
SELECT
id
FROM
main."plans" pl
WHERE
pl.name = 'Premium'), '{"name": "RDS_POSTGRES_STORAGE", "value": 100}');

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
drop table main.features;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CREATE TABLE main.features (
id uuid DEFAULT (md5(((random())::text || (clock_timestamp())::text)))::uuid NOT NULL,
created_on timestamptz DEFAULT CURRENT_TIMESTAMP NOT NULL,
modified_on timestamptz DEFAULT CURRENT_TIMESTAMP NOT NULL,
deleted boolean DEFAULT false NOT NULL,
deleted_on timestamptz,
deleted_by uuid,
created_by uuid NOT NULL,
modified_by uuid,
name varchar(100) NOT NULL,
properties jsonb NOT NULL,
service_id uuid NOT NULL,
CONSTRAINT pk_features_id PRIMARY KEY (id),
CONSTRAINT fk_features_services FOREIGN KEY (service_id) REFERENCES services (id)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE main.subscriptions
DROP COLUMN IF EXISTS plan_details;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE main.subscriptions
ADD COLUMN plan_details jsonb NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Delete from main.services;
Delete from main.features;
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
INSERT INTO main.services (id, created_on, modified_on, deleted, deleted_on, deleted_by, created_by, modified_by, name)
VALUES (
'91f3c086-8794-4a62-98a0-7f02d4e8c103',
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP,
false,
NULL,
NULL,
'123e4567-e89b-12d3-a456-426614174002',
NULL,
'video conferencing service'
);

INSERT INTO main.features (created_by, name, properties, service_id)
VALUES
(
'123e4567-e89b-12d3-a456-426614174002',
'video call',
'{
"enabled": true,
"description": "High quality video calling",
"maxParticipants": 100
}',
'91f3c086-8794-4a62-98a0-7f02d4e8c103'
),
(
'123e4567-e89b-12d3-a456-426614174002',
'chat',
'{
"enabled": true,
"description": "Real-time text chat",
"property4": "value"
}',
'91f3c086-8794-4a62-98a0-7f02d4e8c103'
),
(
'123e4567-e89b-12d3-a456-426614174002',
'recording',
'{
"enabled": false,
"description": "Record meetings",
"priority": 3,
"storageLimit": "5GB"
}',
'91f3c086-8794-4a62-98a0-7f02d4e8c103'
);
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ export const mockSubscription: DataObject<Subscription> = {
endDate: 'sdsd',
status: SubscriptionStatus.ACTIVE,
planId: 'test-plan-id',
planDetails: {},
};
6 changes: 6 additions & 0 deletions services/subscription-service/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {ISubscriptionServiceConfig} from './types';
import {
BillingCycleRepository,
CurrencyRepository,
FeatureRepository,
PlanItemRepository,
PlanRepository,
ResourceRepository,
Expand All @@ -41,6 +42,7 @@ import {
import {
BillinCycleController,
CurrencyController,
FeatureController,
HomePageController,
PingController,
PlanController,
Expand All @@ -58,6 +60,7 @@ import {
Resource,
Service,
Subscription,
Feature,
} from './models';

export class SubscriptionServiceComponent implements Component {
Expand Down Expand Up @@ -98,6 +101,7 @@ export class SubscriptionServiceComponent implements Component {
ResourceRepository,
ServiceRepository,
SubscriptionRepository,
FeatureRepository,
];

this.models = [
Expand All @@ -108,6 +112,7 @@ export class SubscriptionServiceComponent implements Component {
Resource,
Service,
Subscription,
Feature,
];

this.controllers = [
Expand All @@ -121,6 +126,7 @@ export class SubscriptionServiceComponent implements Component {
ServiceController,
SubscriptionController,
PlanSubscriptionController,
FeatureController,
];
}

Expand Down
Loading
Loading