-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: update user and organization metadata #431
feat: update user and organization metadata #431
Conversation
src/utils/metadata/user.js
Outdated
|
||
const { USERS_METADATA, USERS_AUDIENCE } = require('../../constants'); | ||
|
||
class User { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class User { | |
class UserMetadata { |
return redis[name](keys.length, keys, argv); | ||
}); | ||
|
||
return Promise.all(scripts).then((res) => UpdateMetadata.mapScriptResponse($scriptKeys, res)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return Promise.all(scripts).then((res) => UpdateMetadata.mapScriptResponse($scriptKeys, res)); | |
const res = await Promise.all(scripts); | |
return UpdateMetadata.mapScriptResponse($scriptKeys, res); |
const operations = metaOps.map((meta, idx) => UpdateMetadata.handleAudience(pipe, keys[idx], meta)); | ||
return pipe.exec() | ||
.then(handlePipeline) | ||
.then((res) => UpdateMetadata.mapMetaResponse(operations, res)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тут тоже
const res = handlePipeline(await pipe.exec());
return UpdateMetadata.mapMetaResponse(operations, res);
*/ | ||
async batchUpdate(opts) { | ||
const { redis } = this; | ||
assert(!(redis instanceof Pipeline), 'impossible to use with pipeline'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert(!(redis instanceof Pipeline), 'impossible to use with pipeline'); | |
assert(!(redis instanceof Pipeline), 'impossible to use without pipeline'); |
src/utils/metadata/redis/audience.js
Outdated
audienceWork.push( | ||
redis.sadd(this.getAudienceKey(id), audience) | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sadd принимает массив значений, можно упростить:
redis.sadd(this.getAudienceKey(id), audiences)
потому что:
// Arguments to commands are flattened, so the following are the same:
redis.sadd("set", 1, 3, 5, 7);
redis.sadd("set", [1, 3, 5, 7]);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
по сути весь метод .batchAdd не нужен тк он равнозначен .add
src/utils/metadata/user.js
Outdated
* @param audience | ||
* @returns {Promise<void>} | ||
*/ | ||
update(id, hashKey, value, audience) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
я бы добавил проверку наличия всех аргументов, иначе может программист допустить ошибку и забыть добавить какой-то аргумент
assert там использовать или что-то в этом роде
a8bc8e0
to
0b092f6
Compare
* asserts and rf update
const metaOps = Array.isArray(metadata) ? metadata : [metadata]; | ||
|
||
if (metaOps.length !== audiences.length) { | ||
return Promise.reject(new HttpStatusError(400, 'audiences must match metadata entries')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return Promise.reject(new HttpStatusError(400, 'audiences must match metadata entries')); | |
throw new HttpStatusError(400, 'audiences must match metadata entries'); |
* slight api changes
* UserMetadata for->using
* delete all metadata on remove
#436 Dup |
No description provided.