28 lines
744 B
JavaScript
28 lines
744 B
JavaScript
const formatDateAsString = (value) =>
|
|
value instanceof Date ? value.toISOString() : value ?? null
|
|
const { normalizeMediaPath } = require("../../utils/mediaPath")
|
|
|
|
// adapters/responses/publicUser.adapter.js
|
|
function mapUserToPublicUserSummaryResponse(user) {
|
|
return {
|
|
id: user.id,
|
|
username: user.username,
|
|
avatarUrl: normalizeMediaPath(user.avatarUrl) ?? null,
|
|
}
|
|
}
|
|
|
|
function mapUserToPublicUserDetailsResponse(user) {
|
|
return {
|
|
id: user.id,
|
|
username: user.username,
|
|
avatarUrl: normalizeMediaPath(user.avatarUrl) ?? null,
|
|
email: user.email,
|
|
createdAt: formatDateAsString(user.createdAt), // ISO string
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
mapUserToPublicUserSummaryResponse,
|
|
mapUserToPublicUserDetailsResponse,
|
|
}
|