import User from '../entity/User'; import UserAdapterInterface from './UserAdapterInterface'; export default class UserAdapter implements UserAdapterInterface { adapt(json: any, instance: User): User { instance.id = json.id; // TODO: This has to be without the customer_ prefix but backend is sending that way... instance.name = json.name || json.customer_name; instance.surname = json.surname || json.customer_surname; instance.email = json.email; instance.password = null; instance.role = json.role; instance.phone_number = json.phone_number; instance.bookings = json.bookings; instance.authentication_provider = json.authentication_provider; return instance; } prepare(instance: User): any { let object = { id: instance.id, name: instance.name, surname: instance.surname, email: instance.email, phone_number: instance.phone_number, password: instance.password, role: instance.role, authentication_provider: instance.authentication_provider, }; return object; } transformToEntity(json: any): User { return this.adapt(json, new User()); } transformToPayload(instance: User): any { return this.prepare(instance); } }