models/UserIdList.js

export default class UserIdList {
    /**
     * Creates a UserIdList
     * @constructor UserIdList
     * @param {string[]} ids - Array of User IDs.
     * @param {string} providerId - Provider ID.
     */
    constructor(ids, providerId) {
        this.ids = ids || [];
        this.providerId = providerId || null;
    }

    /**
     * Create a list of GetSocial user IDs.
     *
     * @memberof UserIdList
     * @param {string[]} ids - List of GetSocial user IDs.
     * @return {UserIdList} - New identifiers.
     */
    static create(ids) {
        return new UserIdList(ids);
    }

    /**
     * Create a list of user identifiers for given provider ID.
     *
     * @memberof UserIdList
     * @param {string} providerId - Provider ID.
     * @param {string[]} ids - List of GetSocial user IDs.
     * @return {UserIdList} - New identifiers.
     */
     static createWithProvider(providerId, ids) {
        return new UserIdList(ids, providerId);
    }

    /**
     * Creates an Array of strings for the Hades requests
     *
     * @ignore
     * @memberof UserIdList
     * @return {string[]} IDs as strings
     *
     */
     toStrings() {
        return this.providerId
            ? this.ids.map((id) => {
                return id === 'app' || !this.providerId
                    ? id
                    : `${this.providerId}:${id}`;
            })
            : this.ids;
    }
}