const userRepo = require("../repositories/usersRepo") const cache = require("../modules/cache") async function getProfile({ userId }) { const cachedUser = cache.users.get(userId) if (cachedUser) { return cachedUser } return await userRepo.findById(userId) } async function updateProfile({ userId, profile = { displayName, avatarURL } }) { cache.users.delete(userId) return await userRepo.updateProfile(userId, profile.displayName, profile.avatarURL) } async function deleteAccount({ userId }) { return await userRepo.remove(userId) } async function isLocal({ userId }) { return await userRepo.isLocal(userId) } async function createUser({ identifier, serverId, remoteId = null, profile = { displayName, avatarUrl } }) { return await userRepo.create(identifier, serverId, remoteId, profile.displayName, profile.avatarUrl) } async function getShadowUser({ serverId, remoteId }) { return await userRepo.findByServerAndRemoteId(serverId, remoteId) } module.exports = { isLocal, getProfile, createUser, updateProfile, deleteAccount, getShadowUser }