Added apply button and handling

This commit is contained in:
Martin Donnelly 2020-05-25 14:51:52 +01:00
parent 0a7e9ade4e
commit 538275cb37
10 changed files with 112 additions and 11 deletions

View File

@ -18,12 +18,22 @@ 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)
PRIMARY KEY("_id" AUTOINCREMENT),
FOREIGN KEY("rid") REFERENCES "jobs"("_id")
);
CREATE TABLE IF NOT EXISTS "applied" (
"_id" INTEGER NOT NULL UNIQUE,
"aid" INTEGER UNIQUE,
"a" INTEGER NOT NULL,
PRIMARY KEY("_id" AUTOINCREMENT),
FOREIGN KEY("aid") REFERENCES "jobs"("_id")
);
DROP VIEW IF EXISTS "jobsList";
CREATE VIEW jobsList as
select jobs._id, jobs.title, jobs.site, jobs.company, jobs.timestamp, read.d from jobs
select jobs._id, jobs.title, jobs.site, jobs.company, jobs.timestamp, read.d, applied.a from jobs
left join read on read.rid = jobs._id
left join applied on applied.aid = 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

File diff suppressed because one or more lines are too long

25
dist/gfx/star.svg vendored Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg viewBox="0 0 282.3 270.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<linearGradient id="a" gradientUnits="userSpaceOnUse" x1="338.9" x2="322.8" y1="292.1" y2="203.1">
<stop offset="0" stop-color="#e6d82f"/>
<stop offset="1" stop-color="#faf26f"/>
</linearGradient>
<linearGradient id="b" gradientUnits="userSpaceOnUse" x1="391.9" x2="341.2" y1="310.6" y2="310.6">
<stop offset="0" stop-color="#d2c308"/>
<stop offset="1" stop-color="#e8da34"/>
</linearGradient>
</defs>
<g fill-rule="evenodd" transform="translate(-198.9 -145.7)">
<path d="m340.1 292.8l-.4-140.5-32.16 98.6z" fill="url(#a)"/>
<path d="m340.2 152.4l31.45 97.64-31.04 42.7z" fill="#d2c308"/>
<path d="m341.1 292.4l133.8-42.39-103.6-.01z" fill="#faf26f"/>
<path d="m341 293.1l50.85 17.34 83.1-60.32z" fill="#a29910"/>
<path d="m289.1 310.6l50.32-17.12-134.2-43.5z" fill="#d2c308"/>
<path d="m339.6 293.8l-82.67 116.1 32.22-99.1z" fill="#faf26f"/>
<path d="m341.1 293.6l50.78 16.82 31.72 97.69z" fill="url(#b)"/>
<path d="m340.2 348.6l83.08 59.65-82.56-114.4z" fill="#a29910"/>
<path d="m306.9 251.2l33.56 42.72-135.6-43.9z" fill="#faf26f"/>
<path d="m340.2 348.6l-82.9 59.3 83.03-114.5z" fill="#a29910"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -51,7 +51,7 @@ exports.getList = () => {
};
exports.getOne = (id) => {
const sql = 'SELECT * FROM jobs WHERE _id = ?';
const sql = 'SELECT jobs.*, applied.a FROM jobs left join applied on applied.aid = jobs._id WHERE jobs._id == ?';
return new Promise((resolve, reject) => {
db.get(sql, [id], (err, row) => {
@ -80,4 +80,21 @@ exports.touchOne = (data) => {
});
};
exports.appliedOne = (data) => {
const sql = 'INSERT INTO applied VALUES (?,?,?)';
const { aid, a } = data;
return new Promise((resolve, reject) => {
db.run(sql, [null, aid, a], 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

@ -0,0 +1,34 @@
/**
* Created by WebStorm.
* User: martin
* Date: 25/05/2020
* Time: 13:36
*/
const dbmanager = require('../../lib/dbmanager');
exports.markApplied = (req, res) => {
console.log('>markApplied req', req.params);
if(!req.params.id)
return res.status(500).send({
'message': 'Job id missing'
});
const aid = req.params.id;
const a = new Date().getTime();
// touchOne
dbmanager.appliedOne({ aid, a })
.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

@ -0,0 +1,14 @@
/**
* Created by WebStorm.
* User: martin
* Date: 25/05/2020
* Time: 13:36
*/
const apply = require('../controllers/apply.controller');
module.exports = (app) => {
app.route('/apply/:id')
.put(apply.markApplied);
};

View File

@ -38,6 +38,7 @@ app.use(bodyParser.urlencoded({ 'extended': true }));
app.use(bodyParser.json());
require('./routes/jobs.route')(app);
require('./routes/apply.route')(app);
app.listen(serverPort, () => {
console.log(`Server is listening on port ${serverPort}`);