Added view

Added read marking
This commit is contained in:
Martin Donnelly 2020-05-25 10:21:56 +01:00
parent d2f6b3e29c
commit 7c424a069e
7 changed files with 78 additions and 5 deletions

29
db/jobstest.db.sql Normal file
View File

@ -0,0 +1,29 @@
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS "jobs" (
"_id" INTEGER NOT NULL UNIQUE,
"title" TEXT,
"site" TEXT,
"url" TEXT,
"id" TEXT UNIQUE,
"summary" TEXT,
"company" TEXT,
"location" TEXT,
"postdate" TEXT,
"salary" TEXT,
"easyapply" INTEGER,
"timestamp" INTEGER,
PRIMARY KEY("_id" AUTOINCREMENT)
);
CREATE TABLE IF NOT EXISTS "read" (
"_id" INTEGER NOT NULL UNIQUE,
"rid" INTEGER UNIQUE,
"d" INTEGER NOT NULL,
FOREIGN KEY("rid") REFERENCES "jobs"("_id"),
PRIMARY KEY("_id" AUTOINCREMENT)
);
CREATE VIEW jobsList as
select jobs._id, jobs.title, jobs.site, jobs.company, jobs.timestamp, read.d from jobs
left join read on read.rid = jobs._id
order by jobs._id desc;
COMMIT;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -33,7 +33,8 @@ exports.insertOne = (data) => {
exports.getList = () => {
const outgoing = [];
const sql = 'select _id, title, site, company, timestamp from jobs order by _id desc';
// const sql = 'select _id, title, site, company, timestamp from jobs order by _id desc';
const sql = 'select * from jobsList';
return new Promise((resolve, reject) => {
db.all(sql, [], (err, rows) => {
@ -62,5 +63,21 @@ exports.getOne = (id) => {
});
};
exports.touchOne = (data) => {
const sql = 'INSERT INTO read VALUES (?,?,?)';
const { rid, d } = data;
return new Promise((resolve, reject) => {
db.run(sql, [null, rid, d], function(err) {
if (err && err.errno !== 19) {
console.log(err);
reject(err);
}
resolve({});
});
});
};
// select _id, title, site, company, timestamp from jobs order by _id desc;

View File

@ -60,3 +60,29 @@ exports.getJob = (req, res) => {
});
});
};
exports.readJob = (req, res) => {
console.log('>readJob req', req.params);
if(!req.params.id)
return res.status(500).send({
'message': 'Job id missing'
});
const rid = req.params.id;
const d = new Date().getTime();
// touchOne
dbmanager.touchOne({ rid, d })
.then((data) => {
console.log(data);
res.status(200).end();
})
.catch((err) => {
res.status(500).send({
'message': err.message || 'Some error occurred while querying the database.'
});
});
};

View File

@ -13,5 +13,6 @@ module.exports = (app) => {
.get(jobs.getList);
app.route('/jobs/:id')
.get(jobs.getJob);
.get(jobs.getJob)
.put(jobs.readJob);
};