From c10998d519bd7aff6c850be085cb88124f0b4c36 Mon Sep 17 00:00:00 2001 From: Amit Jakubowicz Date: Tue, 3 Apr 2018 07:58:21 +0200 Subject: [PATCH] Works --- functions/lib/index.js | 1 + functions/lib/repository.js | 8 +++++++- functions/package.json | 5 ++++- functions/src/index.ts | 1 + functions/src/repository.ts | 8 +++++++- 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/functions/lib/index.js b/functions/lib/index.js index 61ae8c3..d3ff798 100644 --- a/functions/lib/index.js +++ b/functions/lib/index.js @@ -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 }); diff --git a/functions/lib/repository.js b/functions/lib/repository.js index 26bb98f..ba8e717 100644 --- a/functions/lib/repository.js +++ b/functions/lib/repository.js @@ -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; }); }); } diff --git a/functions/package.json b/functions/package.json index e06c1cd..48f9cad 100644 --- a/functions/package.json +++ b/functions/package.json @@ -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" + } } diff --git a/functions/src/index.ts b/functions/src/index.ts index 1eb8beb..a898bfa 100644 --- a/functions/src/index.ts +++ b/functions/src/index.ts @@ -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 }); diff --git a/functions/src/repository.ts b/functions/src/repository.ts index 54be02b..b39fe15 100644 --- a/functions/src/repository.ts +++ b/functions/src/repository.ts @@ -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 }); }; } \ No newline at end of file