in libs/newsletters-data-client/src/lib/layout-storage/S3LayoutStorage.ts [29:62]
async create(
edition: EditionId,
layout: Layout,
): Promise<SuccessfulStorageResponse<Layout> | UnsuccessfulStorageResponse> {
const parseResult = layoutSchema.safeParse(layout);
if (!parseResult.success) {
return {
ok: false,
message: 'layout in wrong format',
reason: StorageRequestFailureReason.InvalidDataInput,
};
}
try {
const layoutWithSameKeyExists = await this.objectExists(
this.editionIdToKey(edition),
);
if (layoutWithSameKeyExists) {
return {
ok: false,
message: `Layout ${edition} already exists`,
reason: StorageRequestFailureReason.InvalidDataInput,
};
}
} catch (err) {
return {
ok: false,
message: `failed to check if layout for ${edition} exists`,
reason: StorageRequestFailureReason.S3Failure,
};
}
return this.update(edition, layout);
}