39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import { injectable } from 'inversify';
|
|
import { TransformationType } from '../../../entities/library/transformation-type';
|
|
import { Work } from '../../../entities/library/work';
|
|
import { getDeserializedEntityPromise } from '../get-deserialized';
|
|
import { serializeEntityPromise } from '../serialize-entity-promise';
|
|
import { Serializer } from '../serializer';
|
|
|
|
@injectable()
|
|
export class TransformationSerializer extends Serializer<
|
|
TransformationEntityInterface,
|
|
TransformationSerializedInterface
|
|
> {
|
|
public async serialize(entity: TransformationEntityInterface): Promise<TransformationSerializedInterface> {
|
|
const [byWork, ofWork, type] = await Promise.all([
|
|
serializeEntityPromise(entity.byWork),
|
|
serializeEntityPromise(entity.ofWork),
|
|
serializeEntityPromise(entity.type),
|
|
]);
|
|
|
|
return {
|
|
id: entity.id,
|
|
order: entity.order,
|
|
byWork,
|
|
ofWork,
|
|
type,
|
|
};
|
|
}
|
|
|
|
public deserialize(partial: Partial<TransformationSerializedInterface>): Partial<TransformationEntityInterface> {
|
|
return {
|
|
...(partial.id ? { id: partial.id } : {}),
|
|
...(partial.order ? { order: partial.order } : {}),
|
|
...(partial.type ? { type: getDeserializedEntityPromise(partial.type, TransformationType) } : {}),
|
|
...(partial.ofWork ? { ofWork: getDeserializedEntityPromise(partial.ofWork, Work) } : {}),
|
|
...(partial.byWork ? { byWork: getDeserializedEntityPromise(partial.byWork, Work) } : {}),
|
|
};
|
|
}
|
|
}
|