This commit is contained in:
Amit Jakubowicz 2018-04-03 07:58:21 +02:00
parent 07f2537382
commit c10998d519
5 changed files with 20 additions and 3 deletions

View file

@ -16,6 +16,7 @@ exports.isUserAvailable = (req, res) => __awaiter(this, void 0, void 0, function
email: params.email,
username: params.username
});
console.log('got user from repository', JSON.stringify(user));
res.send({
exists: !!user
});

View file

@ -32,6 +32,7 @@ class Repository {
}
static getUser(user) {
return __awaiter(this, void 0, void 0, function* () {
console.log('Search for user', JSON.stringify(user));
let query = datastore
.createQuery('user');
if (user.email) {
@ -42,7 +43,12 @@ class Repository {
}
return yield datastore.runQuery(query)
.then(results => {
return results[0];
console.log('Got results', JSON.stringify(results));
const resultSet = results[0];
if (resultSet.length > 1) {
console.warn('Got more than one user, should have gotten at most one', JSON.stringify(resultSet));
}
return resultSet.length ? resultSet[0] : null;
});
});
}

View file

@ -16,6 +16,9 @@
"typescript": "^2.8.1"
},
"scripts": {
"build": "./node_modules/.bin/tsc"
"build": "./node_modules/.bin/tsc",
"deploy": "gcloud beta functions deploy isUserAvailable --trigger-http",
"logs": "gcloud beta functions logs read"
}
}

View file

@ -9,6 +9,7 @@ export const isUserAvailable = async (req, res) => {
username: params.username as string
})
console.log('got user from repository', JSON.stringify(user))
res.send({
exists: !!user
});

View file

@ -25,6 +25,7 @@ export default class Repository {
}
static async getUser (user: UserKeys) {
console.log('Search for user', JSON.stringify(user))
let query = datastore
.createQuery('user')
@ -37,7 +38,12 @@ export default class Repository {
return await datastore.runQuery(query)
.then(results => {
return results[0]
console.log('Got results', JSON.stringify(results))
const resultSet = results[0]
if (resultSet.length > 1) {
console.warn('Got more than one user, should have gotten at most one', JSON.stringify(resultSet))
}
return resultSet.length ? resultSet[0] : null
});
};
}