Skip to content

Commit

Permalink
Baseline 11
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhoefer committed Apr 27, 2018
1 parent 9ac4498 commit 8ffc60b
Show file tree
Hide file tree
Showing 14 changed files with 317 additions and 133 deletions.
18 changes: 15 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
npm-debug.log
node_modules
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# misc
.DS_Store

npm-debug.log*
yarn-debug.log*
yarn-error.log*

*.iml
.idea/

.env
*.iml

temp.*
temp/*
16 changes: 10 additions & 6 deletions api/licenses.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const db = require('../util/pghelper');

const SELECT_ALL_HEROKU_CONNECT = `SELECT
l.id, l.sfid, l.name, l.sflma__subscriber_org_id__c as org_id, l.sflma__status__c as status,
l.id, l.sfid, l.name, l.sflma__subscriber_org_id__c as org_id, l.sflma__status__c as status, l.sfLma_is_sandbox__c,
l.sflma__install_date__c as install_date, l.LastModifiedDate as modified_date, l.sflma__expiration__c as expiration,
l.sflma__used_licenses__c as used_license_count, l.sflma__package_version__c as package_version_id,
o.instance as instance, o.account_id as account_id, o.account_name as account_name,
Expand All @@ -13,7 +13,7 @@ const SELECT_ALL_HEROKU_CONNECT = `SELECT
INNER JOIN sflma__package__c as p on pv.sflma__package__c = p.sfid`;

const SELECT_ALL = `SELECT
l.id, l.sfid, l.name, l.org_id, l.status,
l.id, l.sfid, l.name, l.org_id, l.status, l.is_sandbox,
l.install_date, l.modified_date, l.expiration,
l.used_license_count, l.package_version_id,
o.instance, o.account_id, o.account_name,
Expand All @@ -27,12 +27,12 @@ const SELECT_ALL = `SELECT
function requestAll(req, res, next) {
let orgId = req.query.org_id;

findAll(orgId, req.query.sort_field, req.query.sort_dir)
findAll(orgId, req.query.status, req.query.sort_field, req.query.sort_dir)
.then((recs) => {return res.send(JSON.stringify(recs))})
.catch(next);
}

async function findAll(orgId, orderByField, orderByDir) {
async function findAll(orgId, status, orderByField, orderByDir) {
let whereParts = ["o.instance IS NOT NULL"],
values = [];

Expand All @@ -41,11 +41,15 @@ async function findAll(orgId, orderByField, orderByDir) {
whereParts.push("o.org_id = $" + values.length);
}

if (status) {
values.push(status);
whereParts.push(`l.status = $${values.length}`)
}

let where = whereParts.length > 0 ? (" WHERE " + whereParts.join(" AND ")) : "";
let sort = ` ORDER BY ${orderByField || "name"} ${orderByDir || "asc"}`;
let limit = " LIMIT 40";

return db.query(SELECT_ALL + where + sort + limit, values);
return db.query(SELECT_ALL + where + sort, values);
}

function requestById(req, res, next) {
Expand Down
15 changes: 14 additions & 1 deletion api/orggroups.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ async function requestUpdate(req, res, next) {
try {
let og = req.body;
await db.update('UPDATE org_group SET name=$1, description=$2 WHERE id=$3', [og.name, og.description, og.id]);

if (og.orgIds) {
await insertOrgMembers(og.id, og.orgIds);
}
return res.send({result: 'ok'});
} catch (err) {
return next(err);
Expand All @@ -71,7 +75,16 @@ async function requestDelete(req, res, next) {
function requestUpgrade(req, res, next) {
push.upgradeOrgGroups([req.params.id], req.body.versions, req.body.scheduled_date)
.then((upgrade) => {return res.json(upgrade)})
.catch((e) => {console.error(e); next(e)})
.catch((e) => {console.error(e); next(e)});
}

async function insertOrgMembers(groupId, orgIds) {
let n = 2;
let params = orgIds.map(v => `($1,$${n++})`);
let values = [groupId].concat(orgIds);
let sql = `INSERT INTO org_group_member (org_group_id, org_id) VALUES ${params.join(",")}
on conflict do nothing`;
await db.insert(sql, values);
}

exports.requestAll = requestAll;
Expand Down
9 changes: 6 additions & 3 deletions api/orgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ const db = require('../util/pghelper');
const push = require('../worker/packagepush');


const SELECT_ALL = `select o.id, o.org_id, o.instance, o.account_name, o.account_id from org o`;
const SELECT_ALL = `select o.id, o.org_id, o.instance, o.is_sandbox, o.account_name, o.account_id from org o`;
const SELECT_MEMBERS = SELECT_ALL +
" INNER JOIN org_group_member AS m ON o.org_id = m.org_id";

const SELECT_WITH_LICENCE = SELECT_ALL +
" INNER JOIN license lc ON o.org_id = lc.org_id";

async function requestAll(req, res, next) {
let limit = " LIMIT 300";
// let limit = " LIMIT 300";
let limit = "";

try {
let orgs = await findAll(req.query.packageId, req.query.packageVersionId, limit, req.query.sort_field, req.query.sort_dir);
Expand Down Expand Up @@ -54,7 +55,9 @@ function requestById(req, res, next) {

function requestUpgrade(req, res, next) {
push.upgradeOrgs([req.params.id], req.body.versions, req.body.scheduled_date)
.then((upgrade) => {return res.json(upgrade)})
.then((upgrade) => {
return res.json(upgrade)
})
.catch((e) => {console.error(e); next(e)});
}

Expand Down
5 changes: 0 additions & 5 deletions api/packageversions.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ async function findAll(sortField, sortDir, status, packageId, packageOrgId, lice
}
whereParts.push(`l.org_id IN (${params.join(",")})`);
values = values.concat(licensedOrgIds);

// values.push('Uninstalled');
// whereParts.push("l.status != $" + values.length);
// values.push('Suspended');
// whereParts.push("l.status != $" + values.length);
}

if (orgGroupIds) {
Expand Down
Loading

0 comments on commit 8ffc60b

Please sign in to comment.