[pl][census] relevant field; auto-filter for moderation
This commit is contained in:
parent
a52475f644
commit
a714e02bae
|
@ -1387,6 +1387,7 @@ census:
|
||||||
edition: '2022'
|
edition: '2022'
|
||||||
start: '2022-02-01T00:00:00+01:00'
|
start: '2022-02-01T00:00:00+01:00'
|
||||||
end: '2022-02-28T23:59:59+02:00'
|
end: '2022-02-28T23:59:59+02:00'
|
||||||
|
relevant: ['osobą niebinarną', 'nie wiem']
|
||||||
questions:
|
questions:
|
||||||
-
|
-
|
||||||
type: 'radio'
|
type: 'radio'
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
-- Up
|
||||||
|
|
||||||
|
ALTER TABLE census ADD COLUMN relevant INTEGER NULL;
|
||||||
|
|
||||||
|
-- Down
|
||||||
|
|
|
@ -41,6 +41,24 @@ const hasFinished = async req => {
|
||||||
return !!byFingerprint;
|
return !!byFingerprint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isRelevant = (answers) => {
|
||||||
|
return global.config.census.relevant.includes(answers['0']);
|
||||||
|
}
|
||||||
|
|
||||||
|
const isTroll = (answers, writins) => {
|
||||||
|
if (Object.values(writins).filter(x => !!x).length) {
|
||||||
|
return null; // unknown, send to moderation
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i in global.config.census.questions) {
|
||||||
|
if (global.config.census.questions[i].type === 'textarea' && answers[i.toString()]) {
|
||||||
|
return null; // unknown, send to moderation
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false; // no free-text provided
|
||||||
|
}
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get('/census/finished', handleErrorAsync(async (req, res) => {
|
router.get('/census/finished', handleErrorAsync(async (req, res) => {
|
||||||
|
@ -48,10 +66,11 @@ router.get('/census/finished', handleErrorAsync(async (req, res) => {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
router.post('/census/submit', handleErrorAsync(async (req, res) => {
|
router.post('/census/submit', handleErrorAsync(async (req, res) => {
|
||||||
const suspicious = await hasFinished(req);
|
const answers = JSON.parse(req.body.answers);
|
||||||
|
const writins = JSON.parse(req.body.writins);
|
||||||
|
|
||||||
const id = ulid();
|
const id = ulid();
|
||||||
await req.db.get(SQL`INSERT INTO census (id, locale, edition, userId, fingerprint, answers, writins, ip, userAgent, acceptLanguage, suspicious) VALUES (
|
await req.db.get(SQL`INSERT INTO census (id, locale, edition, userId, fingerprint, answers, writins, suspicious, relevant, troll) VALUES (
|
||||||
${id},
|
${id},
|
||||||
${global.config.locale},
|
${global.config.locale},
|
||||||
${global.config.census.edition},
|
${global.config.census.edition},
|
||||||
|
@ -59,10 +78,9 @@ router.post('/census/submit', handleErrorAsync(async (req, res) => {
|
||||||
${buildFingerprint(req)},
|
${buildFingerprint(req)},
|
||||||
${req.body.answers},
|
${req.body.answers},
|
||||||
${req.body.writins},
|
${req.body.writins},
|
||||||
null,
|
${await hasFinished(req)},
|
||||||
null,
|
${isRelevant(answers) ? 1 : 0},
|
||||||
null,
|
${isTroll(answers, writins) ? 1 : 0}
|
||||||
${suspicious}
|
|
||||||
)`);
|
)`);
|
||||||
|
|
||||||
return res.json(id);
|
return res.json(id);
|
||||||
|
@ -90,20 +108,20 @@ router.get('/census/count', handleErrorAsync(async (req, res) => {
|
||||||
SELECT COUNT(*) as c FROM census
|
SELECT COUNT(*) as c FROM census
|
||||||
WHERE locale = ${global.config.locale}
|
WHERE locale = ${global.config.locale}
|
||||||
AND edition = ${global.config.census.edition}
|
AND edition = ${global.config.census.edition}
|
||||||
AND (answers LIKE '{"0":"osobą niebinarną"%' OR answers LIKE '{"0":"nie wiem"%') -- TODO polish-specific
|
AND relevant = 1
|
||||||
`)).c,
|
`)).c,
|
||||||
usable: (await req.db.get(SQL`
|
usable: (await req.db.get(SQL`
|
||||||
SELECT COUNT(*) as c FROM census
|
SELECT COUNT(*) as c FROM census
|
||||||
WHERE locale = ${global.config.locale}
|
WHERE locale = ${global.config.locale}
|
||||||
AND edition = ${global.config.census.edition}
|
AND edition = ${global.config.census.edition}
|
||||||
AND (answers LIKE '{"0":"osobą niebinarną"%' OR answers LIKE '{"0":"nie wiem"%') -- TODO polish-specific
|
AND relevant = 1
|
||||||
AND troll = 0
|
AND troll = 0
|
||||||
`)).c,
|
`)).c,
|
||||||
awaiting: (await req.db.get(SQL`
|
awaiting: (await req.db.get(SQL`
|
||||||
SELECT COUNT(*) as c FROM census
|
SELECT COUNT(*) as c FROM census
|
||||||
WHERE locale = ${global.config.locale}
|
WHERE locale = ${global.config.locale}
|
||||||
AND edition = ${global.config.census.edition}
|
AND edition = ${global.config.census.edition}
|
||||||
AND (answers LIKE '{"0":"osobą niebinarną"%' OR answers LIKE '{"0":"nie wiem"%') -- TODO polish-specific
|
AND relevant = 1
|
||||||
AND troll IS NULL
|
AND troll IS NULL
|
||||||
`)).c,
|
`)).c,
|
||||||
});
|
});
|
||||||
|
@ -156,7 +174,7 @@ router.get('/census/moderation/queue', handleErrorAsync(async (req, res) => {
|
||||||
SELECT id, answers, writins FROM census
|
SELECT id, answers, writins FROM census
|
||||||
WHERE locale = ${global.config.locale}
|
WHERE locale = ${global.config.locale}
|
||||||
AND edition = ${global.config.census.edition}
|
AND edition = ${global.config.census.edition}
|
||||||
AND (answers LIKE '{"0":"osobą niebinarną"%' OR answers LIKE '{"0":"nie wiem"%') -- TODO polish-specific
|
AND relevant = 1
|
||||||
AND troll IS NULL
|
AND troll IS NULL
|
||||||
ORDER BY RANDOM()
|
ORDER BY RANDOM()
|
||||||
`);
|
`);
|
||||||
|
|
Reference in New Issue