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: add tenant onboarding source column #26

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
59 changes: 30 additions & 29 deletions facades/tenant-mgmt-facade/src/controllers/tenant.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {verifySignature} from '../utils';
import {HttpErrors} from '@loopback/rest';
import {PaymentMethodEnum, SubscriptionProxyService} from '../services/proxies';
import {Filter, repository} from '@loopback/repository';
import { AnyObject } from '@loopback/repository';
import {AnyObject} from '@loopback/repository';

export class TenantController {
constructor(
Expand Down Expand Up @@ -160,6 +160,7 @@ export class TenantController {
email: details.customer.email,
isPrimary: true,
},
source: 'AWSMARKETPLACE',
domains: [details.customer.email.split('@')[1]],
key: details.appConfig.preferredSubdomain,
address: details.customer.address,
Expand Down Expand Up @@ -267,35 +268,35 @@ export class TenantController {
): Promise<SubscriptionBillDTO[]> {
return this.tenantHelper.getTenantBills(currentUser.id);
}
// Get All Tenants
@authorize({
permissions: [PermissionKey.ViewTenant],
})
@authenticate(STRATEGY.BEARER, {
passReqToCallback: true,
})
@get('/tenants', {
description: 'Retrieve all tenants',
security: OPERATION_SECURITY_SPEC,
responses: {
[STATUS_CODE.OK]: {
description: 'Array of Tenant instances',
content: {
[CONTENT_TYPE.JSON]: {
schema: {
type: 'array',
items: getModelSchemaRef(Tenant, {includeRelations: true}),
},
},
// Get All Tenants
@authorize({
permissions: [PermissionKey.ViewTenant],
})
@authenticate(STRATEGY.BEARER, {
passReqToCallback: true,
})
@get('/tenants', {
description: 'Retrieve all tenants',
security: OPERATION_SECURITY_SPEC,
responses: {
[STATUS_CODE.OK]: {
description: 'Array of Tenant instances',
content: {
[CONTENT_TYPE.JSON]: {
schema: {
type: 'array',
items: getModelSchemaRef(Tenant, {includeRelations: true}),
},
},
},
})
async findTenants(
@inject(AuthenticationBindings.CURRENT_USER)
currentUser: LeadUser,
@param.filter(Tenant) filter?: Filter<Tenant>,
): Promise<AnyObject> {
return this.tenantHelper.getAllTenants(currentUser.id,filter);
}
},
},
})
async findTenants(
@inject(AuthenticationBindings.CURRENT_USER)
currentUser: LeadUser,
@param.filter(Tenant) filter?: Filter<Tenant>,
): Promise<AnyObject> {
return this.tenantHelper.getAllTenants(currentUser.id, filter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ export class CreateTenantWithPlanDTO extends Model {
})
key: string;

@property({
type: 'string',
description:
'Acquisition source of the tenant. Eg. AWS Marketplace, Super Admin Portal, Registration Page.',
})
source: string;

@property({
required: true,
jsonSchema: {
Expand Down
7 changes: 7 additions & 0 deletions facades/tenant-mgmt-facade/src/models/tenant.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ export class Tenant extends UserModifiableEntity {
})
key: string;

@property({
type: 'string',
description:
'Acquisition source of the tenant. Eg. AWS Marketplace, Super Admin Portal, Registration Page.',
})
source: string;

@property({
name: 'spoc_user_id',
description:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'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', '20241009054131-add-tenants-source-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', '20241009054131-add-tenants-source-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,2 @@
ALTER TABLE main.tenants
DROP COLUMN source;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE main.tenants
ADD COLUMN source varchar(255) DEFAULT 'INTERNAL';