-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestsequelizeModule.js
More file actions
146 lines (114 loc) · 2.93 KB
/
Copy pathtestsequelizeModule.js
File metadata and controls
146 lines (114 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
var db = require('./db.js');
var sqlite3 = require('sqlite3').verbose();
var dbConnectionString = 'db/testdb.sqlite';
var moment = require('moment');
db.sequelize.sync().then(function () {
console.log('Everything is synced');
var newMessageText = 'This is a test mesage, mofo, asshole';
//saveNewOrChangedNote(newMessageText, 0, 137);
testFunction();
});
function testFunction() {
db.listMembership.findAll(
{
where: { messageListId: 2 },
order: [
['noteId', 'DESC']
],
limit: 10
}
).then(function (listMembershipRows) {
if (listMembershipRows) {
idsOfInterest = [];
for (i = 0; i < listMembershipRows.length; i++) {
idsOfInterest.push(listMembershipRows[i].noteId);
}
db.noteVersions.findAll(
{
where: { noteId: {$in: idsOfInterest} },
order: [
['noteId', 'DESC']
]
}
).then(function (noteVersionsRows) {
for (i = 0 ; i < noteVersionsRows.length; i++) {
console.log('---------------------------------------------------------');
console.log(noteVersionsRows[i].noteId);
console.log('---------------------------------------------------------');
console.log(noteVersionsRows[i].noteVersionsText);
}
});
}
});
}
function testOldfunction() {
var dateStr = moment().format();
db.notes.create(
{
noteId: 112,
noteText: 'What???????????',
noteTypeId: 0,
creatorId: 0
}
).then(
function () {
console.log('That shit worked');
},
function () {
console.log('That shit DID NOT work');
}
);
};
function saveNewOrChangedNote(theMessage,
userId,
noteId) {
desiredMessage = theMessage;
desiredCreatorId = userId;
desiredNoteId = noteId;
db.notes.create(
{
noteTypeId: 0,
creatorId: userId,
noteId: noteId
}
).then(
function (newNote) {
createNewVersion(newNote.noteId, theMessage)
},
function (errorObject) {
console.log('You cant insert that shit.');
createNewVersion(desiredNoteId, desiredMessage);
}
);
};
function createNewVersion(newNoteId, theMessage) {
var dateStr = moment().format();
db.noteVersions.create(
{
noteId: newNoteId,
noteVersionsText: theMessage,
noteVersionsUpdateTimeStamp: dateStr
}
).then(function (newNoteVersion) {
console.log('Version ID: ' + newNoteVersion.noteVersionsId);
console.log('Message ID: ' + newNoteId);
});
};
//var theMessage = req.body.message;
//var dateStr = moment().format();
//var newNoteId = 0;
//var db = new sqlite3.Database(dbConnectionString);
//db.serialize(function () {
// var theSQL = "INSERT INTO notes (noteText, itemUpdateTimeStamp, creatorId) VALUES (?, ?, ?)";
// //var stmt = db.prepare(theSQL);
// db.run(theSQL, theMessage, dateStr, 0, function (err) {
// console.log(this.lastId);
// newNoteId = this.lastId;
// console.log(newNoteId);
// var retJson = { message: newNoteId };
// res.statusCode = 200;
// res.json(retJson);
// res.end();
// db.close();
// });
//});