mirror of
https://github.com/skishore/makemeahanzi.git
synced 2025-10-30 02:18:16 +08:00
35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
"use strict";
|
|
|
|
this.Glyphs = new Mongo.Collection('glyphs');
|
|
|
|
Glyphs.get = (query) => Glyphs.findOne(query);
|
|
|
|
Glyphs.getNext = (glyph) => {
|
|
const codepoint = glyph ? glyph.codepoint : undefined;
|
|
const next = Glyphs.findOne(
|
|
{codepoint: {$gt: codepoint}}, {sort: {codepoint: 1}});
|
|
return next ? next : Glyphs.findOne({}, {sort: {codepoint: 1}});
|
|
}
|
|
|
|
Glyphs.getPrevious = (glyph) => {
|
|
const codepoint = glyph ? glyph.codepoint : undefined;
|
|
const previous = Glyphs.findOne(
|
|
{codepoint: {$lt: codepoint}}, {sort: {codepoint: -1}});
|
|
return previous ? previous : Glyphs.findOne({}, {sort: {codepoint: -1}});
|
|
}
|
|
|
|
Glyphs.save = (glyph) => {
|
|
check(glyph.character, String);
|
|
assert(glyph.character.length === 1);
|
|
Glyphs.upsert({character: glyph.character}, glyph);
|
|
}
|
|
|
|
// Register the methods above on the server so they are available to the client.
|
|
if (Meteor.isServer) {
|
|
const methods = {};
|
|
const method_names = ['get', 'getNext', 'getPrevious', 'save'];
|
|
method_names.map((name) => methods[`${name}Glyph`] = Glyphs[name]);
|
|
methods.saveGlyphs = (glyphs) => glyphs.map(Glyphs.save);
|
|
Meteor.methods(methods);
|
|
}
|