'use strict';

/**
 * @param {import('../models').Playlist} model
 */
function serializePlaylist(model) {
  return {
    _id: model.id || model._id.toString(),
    name: model.name,
    author: model.author,
    createdAt: model.createdAt,
    description: model.description,
    size: model.media.length,
  };
}

/**
 * @param {Pick<import('../models').User,
 *   '_id' | 'username' | 'slug' | 'roles' | 'avatar' |
 *   'createdAt' | 'updatedAt' | 'lastSeenAt'>} model
 */
function serializeUser(model) {
  return {
    _id: model._id.toString(),
    username: model.username,
    slug: model.slug,
    roles: model.roles,
    avatar: model.avatar,
    createdAt: model.createdAt.toString(),
    updatedAt: model.updatedAt.toString(),
    lastSeenAt: model.lastSeenAt.toString(),
  };
}

exports.serializePlaylist = serializePlaylist;
exports.serializeUser = serializeUser;

@@ -199,16 +199,27 @@
 l.author
+.toString()
 ,%0A    cr
@@ -242,16 +242,30 @@
 reatedAt
+.toISOString()
 ,%0A    de
@@ -693,32 +693,35 @@
 del.createdAt.to
+ISO
 String(),%0A    up
@@ -743,24 +743,27 @@
 updatedAt.to
+ISO
 String(),%0A  
@@ -795,16 +795,19 @@
 eenAt.to
+ISO
 String()

Fix serialization of Dates in user and playlist objects