Skip to content

Commit fadec97

Browse files
committed
React
1 parent 330993f commit fadec97

File tree

355 files changed

+9381
-17886
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

355 files changed

+9381
-17886
lines changed

backend/internal/user.js

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const omissions = () => {
1212
return ["is_deleted"];
1313
}
1414

15+
const DEFAULT_AVATAR = 'https://gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=200&d=mp&r=g';
16+
1517
const internalUser = {
1618
/**
1719
* @param {Access} access
@@ -33,7 +35,6 @@ const internalUser = {
3335
.can("users:create", data)
3436
.then(() => {
3537
data.avatar = gravatar.url(data.email, { default: "mm" });
36-
3738
return userModel.query().insertAndFetch(data).then(utils.omitRow(omissions()));
3839
})
3940
.then((user) => {
@@ -133,7 +134,6 @@ const internalUser = {
133134
}
134135

135136
data.avatar = gravatar.url(data.email || user.email, { default: "mm" });
136-
137137
return userModel.query().patchAndFetchById(user.id, data).then(utils.omitRow(omissions()));
138138
})
139139
.then(() => {
@@ -193,6 +193,11 @@ const internalUser = {
193193
if (typeof thisData.omit !== "undefined" && thisData.omit !== null) {
194194
return _.omit(row, thisData.omit);
195195
}
196+
197+
if (row.avatar === "") {
198+
row.avatar = DEFAULT_AVATAR;
199+
}
200+
196201
return row;
197202
});
198203
},
@@ -299,32 +304,32 @@ const internalUser = {
299304
* @param {String} [search_query]
300305
* @returns {Promise}
301306
*/
302-
getAll: (access, expand, search_query) => {
303-
return access.can("users:list").then(() => {
304-
const query = userModel
305-
.query()
306-
.where("is_deleted", 0)
307-
.groupBy("id")
308-
.allowGraph("[permissions]")
309-
.orderBy("name", "ASC");
310-
311-
// Query is used for searching
312-
if (typeof search_query === "string") {
313-
query.where(function () {
314-
this.where("name", "like", `%${search_query}%`).orWhere(
315-
"email",
316-
"like",
317-
`%${search_query}%`,
318-
);
319-
});
320-
}
307+
getAll: async (access, expand, search_query) => {
308+
await access.can("users:list");
309+
const query = userModel
310+
.query()
311+
.where("is_deleted", 0)
312+
.groupBy("id")
313+
.allowGraph("[permissions]")
314+
.orderBy("name", "ASC");
315+
316+
// Query is used for searching
317+
if (typeof search_query === "string") {
318+
query.where(function () {
319+
this.where("name", "like", `%${search_query}%`).orWhere(
320+
"email",
321+
"like",
322+
`%${search_query}%`,
323+
);
324+
});
325+
}
321326

322-
if (typeof expand !== "undefined" && expand !== null) {
323-
query.withGraphFetched(`[${expand.join(", ")}]`);
324-
}
327+
if (typeof expand !== "undefined" && expand !== null) {
328+
query.withGraphFetched(`[${expand.join(", ")}]`);
329+
}
325330

326-
return query.then(utils.omitRows(omissions()));
327-
});
331+
const res = await query;
332+
return utils.omitRows(omissions())(res);
328333
},
329334

330335
/**

0 commit comments

Comments
 (0)