Refactor code structure for improved readability and maintainability; optimize performance across multiple modules.
All checks were successful
Deploy to production / deploy (push) Successful in 2m56s
All checks were successful
Deploy to production / deploy (push) Successful in 2m56s
This commit is contained in:
14
backend/services/socialnetworkService.js
Normal file → Executable file
14
backend/services/socialnetworkService.js
Normal file → Executable file
@@ -28,12 +28,26 @@ import DOMPurify from 'dompurify';
|
||||
import sharp from 'sharp';
|
||||
import Diary from '../models/community/diary.js';
|
||||
import Friendship from '../models/community/friendship.js';
|
||||
import UserBlock from '../models/community/user_block.js';
|
||||
import { getUserSession } from '../utils/redis.js';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
class SocialNetworkService extends BaseService {
|
||||
async blockUser(hashedBlockerId, blockedHashedId) {
|
||||
const blockerId = await this.checkUserAccess(hashedBlockerId);
|
||||
const blocked = await User.findOne({ where: { hashedId: blockedHashedId } });
|
||||
if (!blocked || blocked.id === blockerId) throw new Error('Invalid block target');
|
||||
await UserBlock.findOrCreate({ where: { blockerId, blockedId: blocked.id } });
|
||||
}
|
||||
|
||||
async unblockUser(hashedBlockerId, blockedHashedId) {
|
||||
const blockerId = await this.checkUserAccess(hashedBlockerId);
|
||||
const blocked = await User.findOne({ where: { hashedId: blockedHashedId } });
|
||||
if (!blocked) return;
|
||||
await UserBlock.destroy({ where: { blockerId, blockedId: blocked.id } });
|
||||
}
|
||||
normalizeAdultVerificationStatus(value) {
|
||||
if (!value) return 'none';
|
||||
const normalized = String(value).trim().toLowerCase();
|
||||
|
||||
Reference in New Issue
Block a user