Added view
Added read marking
This commit is contained in:
parent
d2f6b3e29c
commit
7c424a069e
29
db/jobstest.db.sql
Normal file
29
db/jobstest.db.sql
Normal 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;
|
2
dist/build/bundle.css
vendored
2
dist/build/bundle.css
vendored
File diff suppressed because one or more lines are too long
2
dist/build/bundle.js
vendored
2
dist/build/bundle.js
vendored
File diff suppressed because one or more lines are too long
2
dist/build/bundle.js.map
vendored
2
dist/build/bundle.js.map
vendored
File diff suppressed because one or more lines are too long
@ -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;
|
||||
|
@ -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.'
|
||||
});
|
||||
});
|
||||
};
|
||||
|
@ -13,5 +13,6 @@ module.exports = (app) => {
|
||||
.get(jobs.getList);
|
||||
|
||||
app.route('/jobs/:id')
|
||||
.get(jobs.getJob);
|
||||
.get(jobs.getJob)
|
||||
.put(jobs.readJob);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user