Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return params
}
/** SQL Service **/
const sqlService = {
// SQL type-mapping adapter. Add new types as required.
TYPES: {
BigInt: mssql.BigInt,
Bit: mssql.Bit,
Char: mssql.Char,
DateTimeOffset: mssql.DateTimeOffset,
DateTime: mssql.DateTime,
DateTime2: mssql.DateTime2,
Decimal: mssql.Decimal,
Float: mssql.Float,
Int: mssql.Int,
Numeric: mssql.Numeric,
NVarChar: mssql.NVarChar,
Real: mssql.Real,
SmallInt: mssql.SmallInt,
UniqueIdentifier: mssql.UniqueIdentifier
}
}
// Name of the admin database
sqlService.adminSchema = '[mtc_admin]'
sqlService.initPool = async () => {
if (pool) {
logger.warn('The connection pool has already been initialised')
return
}
function test_table() {
var table = new sql.Table('#temp_table');
table.create = true;
table.columns.add('name', sql.VarChar(sql.MAX), { nullable: false });
table.columns.add('type', sql.Int, { nullable: false });
table.columns.add('amount', sql.Decimal(7, 2), { nullable: false });
table.rows.add('name', 42, 3.50);
table.rows.add('name2', 7, 3.14);
}
ctxTrans.commit(function(err) {
(err === null).should.be.true;
ctxNoTrans.execPrepared(selsql, function(err, records) {
(err === null).should.be.true;
//verify that the new row is returned
records.length.should.equal(1);
}, [{
i1: {
sqlType: nodemssql.Int,
value: rowId
}
}]);
});
}, [{
var getTwoParmVals = function(i1Val, v1Val) {
return [{
v1: {
sqlType: nodemssql.NVarChar,
value: v1Val
}
}, {
i1: {
sqlType: nodemssql.Int,
value: i1Val
}
}];
};
table.columns.add('timepoint', sql.Int, {nullable: true})
} else if (name === 'calendar') {
table.columns.add('service_id', sql.VarChar(100), {nullable: false})
table.columns.add('monday', sql.Bit, {nullable: false})
table.columns.add('tuesday', sql.Bit, {nullable: false})
table.columns.add('wednesday', sql.Bit, {nullable: false})
table.columns.add('thursday', sql.Bit, {nullable: false})
table.columns.add('friday', sql.Bit, {nullable: false})
table.columns.add('saturday', sql.Bit, {nullable: false})
table.columns.add('sunday', sql.Bit, {nullable: false})
table.columns.add('start_date', sql.Date, {nullable: false})
table.columns.add('end_date', sql.Date, {nullable: false})
} else if (name === 'calendar_dates') {
table.columns.add('service_id', sql.VarChar(100), {nullable: false})
table.columns.add('date', sql.Date, {nullable: false})
table.columns.add('exception_type', sql.Int, {nullable: false})
} else {
return null
}
return table
}
function fetchPaginatedInventoryDims(sqlPool, orgModelId, pagesToFetch) {
var incrementalInventory;
if (pagesToFetch>0) {
return sqlPool.request()
.input('inventory_per_page', sql.Int, INVENTORY_PER_PAGE)
.input('transfer_pending_state', sql.Int, 0)
.query('SELECT TOP (@inventory_per_page) * FROM ' + INVENTORY_DIM_TABLE + ' WHERE STOCKUPTRANSFER = @transfer_pending_state')
.then(function (result) {
incrementalInventory = result.recordset;
logger.debug({
message: 'Fetched inventory',
pagesToFetch,
numberOfInventory: incrementalInventory.length,
commandName
});
//Fetch all storeModels for this inventory
return db.collection('StoreModel').find({
"orgModelId": ObjectId(orgModelId)
}).toArray()
})
.then(function (result) {
table.columns.add('route_long_name', sql.VarChar(150), {nullable: false})
table.columns.add('route_desc', sql.VarChar(150), {nullable: true})
table.columns.add('route_type', sql.Int, {nullable: false})
table.columns.add('route_url', sql.VarChar(100), {nullable: true})
table.columns.add('route_color', sql.VarChar(50), {nullable: true})
table.columns.add('route_text_color', sql.VarChar(50), {nullable: true})
} else if (name === 'trips') {
table.columns.add('route_id', sql.VarChar(100), {nullable: false})
table.columns.add('service_id', sql.VarChar(100), {nullable: false})
table.columns.add('trip_id', sql.VarChar(100), {nullable: false})
table.columns.add('trip_headsign', sql.VarChar(100), {nullable: true})
table.columns.add('trip_short_name', sql.VarChar(50), {nullable: true})
table.columns.add('direction_id', sql.Int, {nullable: true})
table.columns.add('block_id', sql.VarChar(100), {nullable: true})
table.columns.add('shape_id', sql.VarChar(100), {nullable: true})
table.columns.add('wheelchair_accessible', sql.Int, {nullable: true})
table.columns.add('bikes_allowed', sql.Int, {nullable: true})
} else if (name === 'stop_times') {
table.columns.add('trip_id', sql.VarChar(100), {nullable: false})
table.columns.add('arrival_time', sql.Time(0), {nullable: false})
table.columns.add('departure_time', sql.Time(0), {nullable: false})
table.columns.add('arrival_time_24', sql.Bit, {nullable: false})
table.columns.add('departure_time_24', sql.Bit, {nullable: false})
table.columns.add('stop_id', sql.VarChar(50), {nullable: false})
table.columns.add('stop_sequence', sql.Int, {nullable: false})
table.columns.add('stop_headsign', sql.VarChar(50), {nullable: true})
table.columns.add('pickup_type', sql.Int, {nullable: true})
table.columns.add('drop_off_type', sql.Int, {nullable: true})
table.columns.add('shape_dist_traveled', sql.VarChar(50), {nullable: true})
table.columns.add('timepoint', sql.Int, {nullable: true})
} else if (name === 'calendar') {
table.columns.add('service_id', sql.VarChar(100), {nullable: false})
function fetchPaginatedProducts(sqlPool, orgModelId, pagesToFetch) {
var incrementalProducts, rowIds;
if (pagesToFetch>0) {
return sqlPool.request()
.input('products_per_page', sql.Int, PRODUCTS_PER_PAGE)
.input('transfer_pending_state', sql.Int, 0)
.query('SELECT TOP (@products_per_page)' +
' VPN, ECORESCOLOR, ECORESCONFIGURATION, ECORESSIZE, ECORESSTYLE, ITEMID, NAME, %%physloc%% ROWID' +
' FROM ' + PRODUCT_TABLE +
' WHERE STOCKUPTRANSFER = @transfer_pending_state')
.then(function (result) {
incrementalProducts = result.recordset;
rowIds = [];
rowIds = _.map(incrementalProducts, function (eachProduct) {
return '0x' + eachProduct.ROWID.toString('hex'); //TODO: find a better way of uniquely recognizing rows
});
logger.debug({
message: 'Fetched products',
pagesToFetch,
numberOfProducts: incrementalProducts.length
});
.then(function (result) {
logger.debug({
message: 'Inserted/updated categories in products in DB',
result: {
upserted: result.nUpserted,
inserted: result.nInserted
},
commandName
});
logger.debug({
message: 'Will delete the inserted/updated products from Azure SQL',
commandName
});
return sqlPool.request()
.input('products_per_page', sql.Int, PRODUCTS_PER_PAGE)
.input('transfer_success_state', sql.Int, 1)
.input('transfer_time', sql.DateTime, new Date())
.query('UPDATE TOP (@products_per_page) ' + PRODUCT_TABLE +
' SET STOCKUPTRANSFER = @transfer_success_state, STOCKUPTRANSFERTIME = @transfer_time' +
' WHERE %%physloc%% IN (' + rowIds + ')');
})
.then(function (result) {