Skip to content
This repository was archived by the owner on Jan 2, 2024. It is now read-only.

Commit 87ad4db

Browse files
committed
Eslint config and fixes
1 parent 72cfc22 commit 87ad4db

File tree

4 files changed

+53
-1424
lines changed

4 files changed

+53
-1424
lines changed

.eslintrc.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"extends": "airbnb-base",
3-
"rules": {
4-
"sort-keys": "warn",
5-
"sort-vars": "warn"
2+
"extends": "loopback",
3+
"parserOptions": {
4+
"ecmaVersion": 2018,
5+
"sourceType": "module"
66
}
77
}

lib/google-cloud-datastore-database.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
/* eslint-disable radix */
2-
/* eslint-disable no-unused-vars */
3-
/* eslint-disable no-undef */
4-
/* eslint-disable class-methods-use-this */
5-
/* eslint-disable no-param-reassign */
6-
/* eslint-disable no-use-before-define */
7-
/* eslint-disable prefer-destructuring */
8-
/* eslint-disable no-underscore-dangle */
9-
/* eslint-disable consistent-return */
101
const Datastore = require('@google-cloud/datastore');
112
const util = require('util');
123
const Connector = require('loopback-connector').Connector;
@@ -47,8 +38,13 @@ class GoogleCloudDatastore {
4738
* @param {String} key The id value for this document
4839
*/
4940
createEntity(obj, key) {
50-
const data = Object.assign(obj, { id: key.name });
51-
return { data, key };
41+
const data = Object.assign(obj, {
42+
id: key.name,
43+
});
44+
return {
45+
data,
46+
key,
47+
};
5248
}
5349

5450
/**
@@ -164,12 +160,14 @@ class GoogleCloudDatastore {
164160
* @param {Object} where The filter
165161
*/
166162
buildQuery(model, where) {
167-
const filters = Object.keys(where).map(key => ({ [key]: where[key] }));
163+
const filters = Object.keys(where).map((key) => ({
164+
[key]: where[key],
165+
}));
168166

169167
let query = this.db.createQuery(model);
170168

171169
for (let i = 0; i < filters.length; i += 1) {
172-
query = this.addFilterToQuery(query, filter[i]);
170+
query = this.addFilterToQuery(query, filters[i]);
173171
}
174172

175173
return query;
@@ -240,8 +238,13 @@ class GoogleCloudDatastore {
240238
*/
241239
async findOrCreate(model, filter, data, options, callback) {
242240
try {
243-
const newData = Object.assign(data, { id: filter.where.id });
244-
const find = await this.findById(model, newData.id);
241+
const where = filter ? filter.where : undefined;
242+
const id = where ? where.id : 0;
243+
244+
const newData = Object.assign(data, {
245+
id,
246+
});
247+
const find = await this.findById(model, id);
245248

246249
if (find.length > 0) {
247250
callback(null, find);
@@ -321,7 +324,9 @@ class GoogleCloudDatastore {
321324

322325
if (!exist) throw new Error('Entity not found');
323326

324-
const newData = Object.assign(data, { id });
327+
const newData = Object.assign(data, {
328+
id,
329+
});
325330

326331
await this.addOrUpdateEntity(model, newData, 'update');
327332

@@ -376,6 +381,7 @@ class GoogleCloudDatastore {
376381
*/
377382
async updateOrCreate(model, data, options, callback) {
378383
try {
384+
const id = data ? data.id : undefined;
379385
const result = await this.updateInternal(model, id, data);
380386

381387
callback(null, result);
@@ -445,7 +451,7 @@ class GoogleCloudDatastore {
445451
*/
446452
async destroyById(model, id, options, callback) {
447453
try {
448-
const result = await this.deleteData(model, entityId, null);
454+
const result = await this.deleteData(model, id, null);
449455

450456
callback(null, result);
451457
} catch (error) {

0 commit comments

Comments
 (0)