Skip to content

Commit

Permalink
feat(subscription-service): add ability to custom plan configuration
Browse files Browse the repository at this point in the history
add ability to custom plan configuration

GH-31
  • Loading branch information
Surbhi-sharma1 committed Jul 17, 2024
1 parent 3453011 commit 9458064
Show file tree
Hide file tree
Showing 24 changed files with 2,586 additions and 863 deletions.
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: {},
};
7 changes: 7 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,7 +60,9 @@ import {
Resource,
Service,
Subscription,
Feature,
} from './models';
import { features } from 'process';

Check failure on line 65 in services/subscription-service/src/component.ts

View workflow job for this annotation

GitHub Actions / npm_test

'features' is defined but never used

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

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

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

Expand Down
Loading

0 comments on commit 9458064

Please sign in to comment.