Dev database

This commit is contained in:
Ben Grant 2021-04-12 13:06:10 +10:00
parent 01a9b55b6a
commit ad9863f2de
10 changed files with 17 additions and 13 deletions

View file

@ -24,7 +24,7 @@ module.exports = async (req, res) => {
const currentTime = dayjs().unix();
const entity = {
key: req.datastore.key(['Event', eventId]),
key: req.datastore.key([req.types.event, eventId]),
data: {
name: name,
created: currentTime,

View file

@ -6,8 +6,8 @@ module.exports = async (req, res) => {
const { person } = req.body;
try {
const event = (await req.datastore.get(req.datastore.key(['Event', eventId])))[0];
const query = req.datastore.createQuery('Person')
const event = (await req.datastore.get(req.datastore.key([req.types.event, eventId])))[0];
const query = req.datastore.createQuery(req.types.person)
.filter('eventId', eventId)
.filter('name', person.name);
let personResult = (await req.datastore.runQuery(query))[0][0];
@ -23,7 +23,7 @@ module.exports = async (req, res) => {
}
const entity = {
key: req.datastore.key('Person'),
key: req.datastore.key(req.types.person),
data: {
name: person.name.trim(),
password: hash,

View file

@ -2,7 +2,7 @@ module.exports = async (req, res) => {
const { eventId } = req.params;
try {
const event = (await req.datastore.get(req.datastore.key(['Event', eventId])))[0];
const event = (await req.datastore.get(req.datastore.key([req.types.event, eventId])))[0];
if (event) {
res.send({

View file

@ -2,7 +2,7 @@ module.exports = async (req, res) => {
const { eventId } = req.params;
try {
const query = req.datastore.createQuery('Person').filter('eventId', eventId);
const query = req.datastore.createQuery(req.types.person).filter('eventId', eventId);
let people = (await req.datastore.runQuery(query))[0];
people = people.map(person => ({
name: person.name,

View file

@ -5,7 +5,7 @@ module.exports = async (req, res) => {
const { person } = req.body;
try {
const query = req.datastore.createQuery('Person')
const query = req.datastore.createQuery(req.types.person)
.filter('eventId', eventId)
.filter('name', personName);
let personResult = (await req.datastore.runQuery(query))[0][0];

View file

@ -5,8 +5,8 @@ module.exports = async (req, res) => {
let personCount = null;
try {
const eventQuery = req.datastore.createQuery(['__Stat_Kind__']).filter('kind_name', 'Event');
const personQuery = req.datastore.createQuery(['__Stat_Kind__']).filter('kind_name', 'Person');
const eventQuery = req.datastore.createQuery(['__Stat_Kind__']).filter('kind_name', req.types.event);
const personQuery = req.datastore.createQuery(['__Stat_Kind__']).filter('kind_name', req.types.person);
eventCount = (await req.datastore.runQuery(eventQuery))[0][0].count;
personCount = (await req.datastore.runQuery(personQuery))[0][0].count;

View file

@ -5,7 +5,7 @@ module.exports = async (req, res) => {
const { person } = req.body;
try {
const query = req.datastore.createQuery('Person')
const query = req.datastore.createQuery(req.types.person)
.filter('eventId', eventId)
.filter('name', personName);
let personResult = (await req.datastore.runQuery(query))[0][0];