JSON schema change, input item.duration in minutes and convert to hours

This commit is contained in:
matthieu42morin 2024-03-20 16:17:33 +01:00
parent 918a02e6d2
commit 44ad99d5a7
3 changed files with 45 additions and 5 deletions

View File

@ -1,12 +1,15 @@
<script lang="ts"> <script lang="ts">
import { getImageLink } from "$lib/images"; import { getImageLink } from '$lib/images';
import type { Service } from '$lib/types/service';
import convertMinutesToHours from '$lib/utils/minToH';
export let item: Service['items'][number];
export let item: any = {};
</script> </script>
<a href="/sluzby/{item.id}" id="{item.id}"class="w-72 card variant-glass-secondary mx-2 my-4 duration-500 hover:scale-105 hover:shadow-xl shadow-md"> <a href="/sluzby/{item.id}" id="{item.id}"class="w-72 card variant-glass-secondary mx-2 my-4 duration-500 hover:scale-105 hover:shadow-xl shadow-md">
<header> <header>
<img src={getImageLink({id: item.id, w: 288, h: 320 })} class="bg-black/50 object-cover aspect-[9/10] rounded-t-xl" alt="Post" /> <img src={getImageLink({id: item.id, w: 288, h: 320 })} class="bg-black/50 object-cover aspect-[9/10] rounded-t-xl" alt="Post" loading="lazy" />
</header> </header>
<!-- <div class="img" style="background-image: url('/images/services/{item.id}.jpg');"/> --> <!-- <div class="img" style="background-image: url('/images/services/{item.id}.jpg');"/> -->
<div class="flex flex-col px-4 py-3 w-72 h-full"> <div class="flex flex-col px-4 py-3 w-72 h-full">
@ -29,7 +32,8 @@
<footer class="justify-self-end align-bottom"> <footer class="justify-self-end align-bottom">
<div class="flex flex-col md:flex-row md:justify-between items-center"> <div class="flex flex-col md:flex-row md:justify-between items-center">
<p class=" text-lg text-surface-900 font-semibold text-right"> <p class=" text-lg text-surface-900 font-semibold text-right">
{typeof item.price === 'number' ? `${item.price},-` : item.price}{typeof item.duration === 'number' ? `/${item.duration}h` : ''} {typeof item.price === 'number' ? `${item.price},-` : item.price}
{typeof item.duration === 'number' ? `/${convertMinutesToHours(item.duration)}` : ''}
</p> </p>
<a <a
href="https://app.cal.com/kkosmetickysalon/{item.id}" href="https://app.cal.com/kkosmetickysalon/{item.id}"

20
src/lib/utils/minToH.cjs Normal file
View File

@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function convertMinutesToHours(minutes) {
try {
var hours = Math.floor(minutes / 60);
var mins = minutes % 60;
if (hours) {
console.log("".concat(hours, "h ").concat(mins, "m"));
return "".concat(hours, "h ").concat(mins, "m");
}
else
console.log("".concat(mins, "m"));
return "".concat(mins, "m");
}
catch (error) {
console.error("I don't think that's time: ".concat(error));
process.exit(1); // Exit with non-zero code to signal failure
}
}
exports.default = convertMinutesToHours;

16
src/lib/utils/minToH.ts Normal file
View File

@ -0,0 +1,16 @@
export default function convertMinutesToHours(minutes:number) {
try {
const hours = Math.floor(minutes / 60);
const mins = minutes % 60;
if (hours) {
console.log(`${hours}h ${mins}m`)
return `${hours}h ${mins}m`
}
else console.log(`${mins}m`); return `${mins}m`
} catch (error) {
console.error(`I don't think that's time: ${error}`);
process.exit(1); // Exit with non-zero code to signal failure
}
}