56
loading...
This website collects cookies to deliver better user experience
thumbnailUrl
should be removed, a new property name
with value Mario
(or whatever string value you like) should be added to the photo object. As well, as a timestamp with the current time should be added to the array of photo albums.interface Photo {
albumId: number;
id: number;
title: string;
url: string;
thumbnailUrl: string;
}
interface Photo {
albumId: number;
id: number;
name: string;
title: string;
url: string;
}
Array<Photo>
interface PhotoAlbums {
timestamp: Date;
data: Array<Photo>;
}
transform.js
in the project folder, which is going to contain the transform functions.touch transform.js
function transformPhoto(photo) {
return {
albumId: photo.albumId,
id: photo.id,
name: 'Mario',
title: photo.title,
url: photo.url,
};
}
module.exports = { transformPhoto };
photoAlbum
, a timestamp with current time should be added and the array with photos should be moved into the new property data
.function addTimeStamp(photoAlbum) {
return {
data: photoAlbum,
timeStamp: new Date(),
};
}
module.exports = { transformPhoto, addTimeStamp };
orchestrateEtlPipeline()
in index.js
and After the request is done, we map over each photo object in each photoAlbum to apply the transformation with the transformPhoto()
function. Then we out the result.const { getPhotos } = require('./extract');
const { addTimeStamp, transformPhoto } = require('./transform');
const orchestrateEtlPipeline = async () => {
try {
// EXTRACT
const allPhotoAlbums = Promise.all([
getPhotos(1),
getPhotos(2),
getPhotos(3),
]);
const [
photoAlbum1,
photoAlbum2,
photoAlbum3,
] = await allPhotoAlbums;
// TRANSFORM
let transformedPhotoAlbum1 = photoAlbum1.map(photo =>
transformPhoto(photo),
);
let transformedPhotoAlbum2 = photoAlbum2.map(photo =>
transformPhoto(photo),
);
let transformedPhotoAlbum3 = photoAlbum3.map(photo =>
transformPhoto(photo),
);
console.log(
transformedPhotoAlbum1[0],
transformedPhotoAlbum2[0],
transformedPhotoAlbum3[0],
); // log first photo object of each transformed photoAlbum
// TODO - LOAD
} catch (error) {
console.error(error);
}
};
orchestrateEtlPipeline();
albumId
, id
, name
, title
and url
, the thumbnailUrl
property should be removed. Now we have to transform the photoAlbum and add the timeStamp
. We also output the timestamp.const { getPhotos } = require('./extract');
const { addTimeStamp, transformPhoto } = require('./transform');
const orchestrateEtlPipeline = async () => {
try {
// EXTRACT
const allPhotoAlbums = Promise.all([
getPhotos(1),
getPhotos(2),
getPhotos(3),
]);
const [
photoAlbum1,
photoAlbum2,
photoAlbum3,
] = await allPhotoAlbums;
// TRANSFORM
let transformedPhotoAlbum1 = photoAlbum1.map(photo =>
transformPhoto(photo),
);
let transformedPhotoAlbum2 = photoAlbum2.map(photo =>
transformPhoto(photo),
);
let transformedPhotoAlbum3 = photoAlbum3.map(photo =>
transformPhoto(photo),
);
console.log(
transformedPhotoAlbum1[0],
transformedPhotoAlbum2[0],
transformedPhotoAlbum3[0],
); // log first photo object of each transformed photoAlbum
transformedPhotoAlbum1 = addTimeStamp(transformedPhotoAlbum1);
transformedPhotoAlbum2 = addTimeStamp(transformedPhotoAlbum2);
transformedPhotoAlbum3 = addTimeStamp(transformedPhotoAlbum3);
console.log(
transformedPhotoAlbum1.timeStamp,
transformedPhotoAlbum2.timeStamp,
transformedPhotoAlbum3.timeStamp,
); // log timestamp
console.log(transformedPhotoAlbum1);
// TODO - LOAD
} catch (error) {
console.error(error);
}
};
orchestrateEtlPipeline();