git ssb

0+

Rômulo Alves / dat-letnice



Tree: ccc34dfd351fd863de680736e90b24f449a31a13

Files: ccc34dfd351fd863de680736e90b24f449a31a13 / lib / appointment.js

1006 bytesRaw
1const newId = require('monotonic-timestamp-base36');
2
3const { toArchiveOrigin } = require('./util');
4
5function getNewAppointmentUrl(archiveUrl, id) {
6 return `${archiveUrl}/appointments/${id || newId()}.json`;
7}
8
9module.exports = class Appointment {
10 constructor (lib) {
11 this.db = lib.db;
12 }
13
14 async getByYear (year) {
15 await this.db.appointments
16 .where('year').equals(year)
17 .toArray();
18 }
19
20 async getByDate (year, month, day) {
21 const date = new Date(year, month, day);
22 const initialDate = date.getTime();
23 const finalDate = date.setHours(24);
24
25 await this.db.appointments.query()
26 .where('timestamp').between(initialDate, finalDate)
27 .toArray();
28 }
29
30 async insert (archive, { timestamp, label, year }) {
31 const archiveUrl = toArchiveOrigin(archive);
32 const key = newId();
33 const url = getNewAppointmentUrl(archiveUrl, key);
34
35 await this.db.appointments.put(url, { key, year, timestamp, label, createdAt: Date.now() });
36
37 return url;
38 }
39};

Built with git-ssb-web