openvibers/openvibe.design Commits

/api/v1/glyphs/drafts carries each draft's solid twin (#99)

OP OpenVibers committed 12 days ago · 684bf225b9 · 2 files, +2 −1

#96 stored solid_svg but the API mapped its fields one by one and left it out; it is in each draft now (null when
there is none), so Shared's pull can take the solid with the line drawing.

Changes

ddiff --git a/server/http/icons.js b/server/http/icons.js
iindex 72f4f5b..d2afd2f 100644
---- a/server/http/icons.js
++++ b/server/http/icons.js
@@@ -230,7 +230,7 @@ function createIconRoutes(ctx) {
if (status !== 'approved' && !isAdmin(req)) return problem(res, req, 403, 'design.glyph_drafts_private', 'Only approved drafts are public.');
if (!['approved', 'draft', 'rejected'].includes(status)) return problem(res, req, 422, 'design.invalid', 'status is approved, draft or rejected.');
const rows = await drafts.list({ status, limit: 500 });
-- res.set('Cache-Control', status === 'approved' ? 'public, max-age=300' : 'private, no-store').json({ drafts: rows.map((d) => ({ id: d.id, name: d.name, sentence: d.sentence, svg: d.svg, model: d.model, status: d.status, created_at: d.created_at, reviewed_at: d.reviewed_at })) });
++ res.set('Cache-Control', status === 'approved' ? 'public, max-age=300' : 'private, no-store').json({ drafts: rows.map((d) => ({ id: d.id, name: d.name, sentence: d.sentence, svg: d.svg, solid_svg: d.solid_svg || null, model: d.model, status: d.status, created_at: d.created_at, reviewed_at: d.reviewed_at })) });
});
return r;
}
ddiff --git a/test/icons.test.js b/test/icons.test.js
iindex 54aee1e..f977dba 100644
---- a/test/icons.test.js
++++ b/test/icons.test.js
@@@ -219,6 +219,7 @@ const form = (fields) => ({ body: new URLSearchParams(fields).toString(), header
assert.equal(list[0].name, 'hot-tub');
assert.equal(list[0].status, 'approved');
assert.ok(clean(list[0].svg).ok, 'what is served passed the validator');
++ assert.ok('solid_svg' in list[0], 'each draft carries its solid twin (or null), for the Shared pull');
assert.ok(!('subject' in list[0]), 'who asked stays private');
assert.equal((await t.get('/api/v1/glyphs/drafts?status=rejected')).status, 403);
assert.equal((await t.get('/api/v1/glyphs/drafts?status=nope', { as: boss })).status, 422);