Skip to content

Commit 8ce3ea7

Browse files
committed
sql model is now tested
1 parent e4a918d commit 8ce3ea7

File tree

5 files changed

+33
-28
lines changed

5 files changed

+33
-28
lines changed

TODO.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
|:------|:------:|:------
44
| app.js | 62 | Write a complete Documentation for this project
55
| config/index.js | 12 | Test for production and development senarios
6-
| models/Tests.js | 223 | Test transactions
6+
| models/Tests.js | 95 | Test transactions
77
| models/index.js | 14 | Automatically generate tests with the schema structure
88
| routes/index.js | 298 | Test API versioning
99
| routes/index.js | 299 | Test rate limiting
@@ -14,6 +14,6 @@
1414
| routes/index.js | 304 | Make Log requests testable and write unit tests for it
1515
| routes/index.js | 305 | Develop the route loader into a separate node module to be publish on npm
1616
| routes/index.js | 306 | Develop all services onto separate node module to be publish on npm
17+
| services/logger/index.js | 36 | Test Error Handler
1718
| services/queue/clock.js | 11 | work on a clock functionality so kue can support scheduled jobs
18-
| services/queue/clock.js | 12 | Use the cron package here https://www.npmjs.com/package/cron for timer
19-
| services/logger/index.js | 36 | Test Error Handler
19+
| services/queue/clock.js | 12 | Use the cron package here https://www.npmjs.com/package/cron for timer

config/development.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ module.exports = {
2929
SQLDatabase: process.env.SQL_DATABASE || 'snipe',
3030
SQLHost: process.env.SQL_HOST || '192.168.99.100',
3131
SQLPort: process.env.SQL_PORT || 3306,
32-
SQLDriver: process.env.SQL_DRIVER || 'mysql' //'mysql'|'sqlite'|'postgres'|'mssql'
32+
SQLDriver: process.env.SQL_DRIVER || 'mysql', //'mysql'|'sqlite'|'postgres'|'mssql'
33+
SQLTimezone: process.env.SQL_TIMEZONE || '+01:00'
3334
};

config/production.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ module.exports = {
2929
SQLDatabase: process.env.SQL_DATABASE || 'snipe',
3030
SQLHost: process.env.SQL_HOST || 'localhost',
3131
SQLPort: process.env.SQL_PORT || 3306,
32-
SQLDriver: process.env.SQL_DRIVER || 'mysql' //'mysql'|'sqlite'|'postgres'|'mssql'
32+
SQLDriver: process.env.SQL_DRIVER || 'mysql', //'mysql'|'sqlite'|'postgres'|'mssql'
33+
SQLTimezone: process.env.SQL_TIMEZONE || '+01:00'
3334
};

services/database/sql.js

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,33 @@ var Sequelize = require('sequelize');
77
var debug = require('debug')('sql');
88

99
var Op = Sequelize.Op;
10+
// enable only operators that you need
1011
var operatorsAliases = {
11-
$and: Op.and,
12-
$or: Op.or,
12+
// $and: Op.and,
13+
// $or: Op.or,
1314
$gt: Op.gt,
1415
$gte: Op.gte,
1516
$lt: Op.lt,
1617
$lte: Op.lte,
17-
$ne: Op.ne,
18-
$eq: Op.eq,
19-
$not: Op.not,
20-
$between: Op.between,
21-
$notBetween: Op.notBetween,
22-
$in: Op.in,
23-
$notIn: Op.notIn,
18+
// $ne: Op.ne,
19+
// $eq: Op.eq,
20+
// $not: Op.not,
21+
// $between: Op.between,
22+
// $notBetween: Op.notBetween,
23+
// $in: Op.in,
24+
// $notIn: Op.notIn,
2425
$like: Op.like,
25-
$notLike: Op.notLike,
26-
$iLike: Op.iLike, // PG Only
27-
$notILike: Op.notILike, // PG Only
28-
$regexp: Op.regexp, // PG/mySQL Only
29-
$notReqexp: Op.notRegexp, // PG/mySQL Only
30-
$iRegexp: Op.iRegexp, // PG Only
31-
$notIRegexp: Op.notIRegexp, // PG Only
32-
$overlap: Op.overlap, // PG Only
33-
$contains: Op.contains, // PG Only
34-
$contained: Op.contained, // PG Only
35-
$any: Op.any // PG Only
26+
// $notLike: Op.notLike,
27+
// $iLike: Op.iLike, // PG Only
28+
// $notILike: Op.notILike, // PG Only
29+
// $regexp: Op.regexp, // PG/mySQL Only
30+
// $notReqexp: Op.notRegexp, // PG/mySQL Only
31+
// $iRegexp: Op.iRegexp, // PG Only
32+
// $notIRegexp: Op.notIRegexp, // PG Only
33+
// $overlap: Op.overlap, // PG Only
34+
// $contains: Op.contains, // PG Only
35+
// $contained: Op.contained, // PG Only
36+
// $any: Op.any // PG Only
3637
};
3738

3839
var options = { operatorsAliases: operatorsAliases };
@@ -45,10 +46,13 @@ options.pool = {
4546
acquire: 30000,
4647
idle: 10000
4748
};
49+
options.timezone = config.SQLTimezone;
4850
// SQLite only
4951
// options.storage = 'path/to/database.sqlite';
5052

51-
options.logging = false;
53+
options.logging = function(log){
54+
return (process.env.NODE_ENV === 'production') ? false : debug(log);
55+
};
5256

5357
var sequelize = new Sequelize(config.SQLDatabase, config.SQLUsername, config.SQLPassword, options);
5458

services/queue/jobs.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ split = _.flattenDeep(split);
9292
var task;
9393
if(model){
9494
if(isSQL){
95-
console.log('mememem: ',dataClone);
96-
task = models[model].update(dataClone,{ tags: split.join(', ')} );
95+
task = models[model].update({ tags: split.join(', ')}, {where: dataClone} );
9796
}else{
9897
if(update){
9998
task = models[model].update(dataClone,{ $set: { updatedAt: new Date(Date.now()).toISOString() }, $addToSet: {tags: {$each: split}} });

0 commit comments

Comments
 (0)