Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions app/(client)/history/detail/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,15 @@ export default function Page() {

evoluJsonObjectFrom(
eb
.selectFrom("itemRevision")
.select(["itemRevision.label as label"])
.selectFrom("item")
.select(["item.label as label"])
.whereRef(
"itemRevision.id",
"item.id",
"=",
"paymentItemLine.itemRevisionId",
"paymentItemLine.itemId",
)
.where(
"itemRevision.isDeleted",
"is not",
sqliteTrue,
)
.where("itemRevision.label", "is not", null)
.where("item.isDeleted", "is not", sqliteTrue)
.where("item.label", "is not", null)
.$narrowType<{
label: KyselyNotNull;
}>(),
Expand Down
16 changes: 6 additions & 10 deletions app/(client)/history/detail/receive/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,15 @@ export default function Page() {

evoluJsonObjectFrom(
eb
.selectFrom("itemRevision")
.select(["itemRevision.label as label"])
.selectFrom("item")
.select(["item.label as label"])
.whereRef(
"itemRevision.id",
"item.id",
"=",
"paymentItemLine.itemRevisionId",
"paymentItemLine.itemId",
)
.where(
"itemRevision.isDeleted",
"is not",
sqliteTrue,
)
.where("itemRevision.label", "is not", null)
.where("item.isDeleted", "is not", sqliteTrue)
.where("item.label", "is not", null)
.$narrowType<{
label: KyselyNotNull;
}>(),
Expand Down
12 changes: 6 additions & 6 deletions app/admin/(private)/ai-assistant/ai-assistant-chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
createItemToolName,
} from "@/lib/ai/item-assistant";
import { createQuery } from "@/lib/evolu";
import { createItem } from "@/lib/item/service";
import { createCatalogItem } from "@/lib/item/service";
import { NonEmptyString, NonEmptyString255 } from "@/lib/shared/types";
import { decimalStringToMinorUnits } from "@/lib/shared/zod/money-codec";

Expand Down Expand Up @@ -153,10 +153,10 @@ export function AiAssistantChat() {
};
}

const item = createItem({
const catalogItem = createCatalogItem({
evolu,
})({
item: {
catalogItem: {
deviceId: account.device.id,
label: NonEmptyString255(input.label.trim()),
price,
Expand All @@ -172,12 +172,12 @@ export function AiAssistantChat() {
},
});

toast.success(`Položka "${item.label}" byla vytvořena.`);
toast.success(`Položka "${catalogItem.label}" byla vytvořena.`);

return {
success: true,
message: `Položka "${item.label}" byla vytvořena.`,
itemId: item.id,
message: `Položka "${catalogItem.label}" byla vytvořena.`,
itemId: catalogItem.id,
};
},
}),
Expand Down
8 changes: 4 additions & 4 deletions app/admin/(private)/catalog/categories/detail/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ export default function Home() {
() =>
createQuery((db) =>
db
.selectFrom("item")
.select(["item.id as id"] as const)
.where("item.isDeleted", "is not", sqliteTrue)
.where("item.categoryId", "=", id as Id),
.selectFrom("catalogItem")
.select(["catalogItem.id as id"] as const)
.where("catalogItem.isDeleted", "is not", sqliteTrue)
.where("catalogItem.categoryId", "=", id as Id),
),
[id],
);
Expand Down
118 changes: 59 additions & 59 deletions app/admin/(private)/catalog/detail/history/item-history-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import type {
} from "@/lib/shared/types";
import { formatDateTime, formatMoney } from "@/lib/shared/utils/format";

type ItemRevisionRow = {
type ItemRow = {
id: Id;
deviceId: Id | null;
itemId: Id | null;
Expand Down Expand Up @@ -98,7 +98,7 @@ const toCurrentItemDiffData = (row: CurrentItemRow): DiffRowData => ({
productCodeValue: row.productCodeValue,
});

const toRevisionDiffData = (row: ItemRevisionRow): DiffRowData => ({
const toRevisionDiffData = (row: ItemRow): DiffRowData => ({
label: row.label,
price: row.price,
currency: row.currency,
Expand All @@ -124,7 +124,7 @@ const createColumns = (
t: TFunction,
currentItem: CurrentItemRow | undefined,
diffLabels: Record<string, string>,
): ColumnDef<ItemRevisionRow>[] => [
): ColumnDef<ItemRow>[] => [
{
accessorKey: "createdAt",
header: createSortableHeader(t("items:detail.history.columns.changedAt")),
Expand Down Expand Up @@ -221,20 +221,20 @@ const createColumns = (
];

const sortingFields = {
id: "itemRevision.id",
deviceId: "itemRevision.deviceId",
itemId: "itemRevision.itemId",
categoryId: "itemRevision.categoryId",
createdAt: "itemRevision.createdAt",
label: "itemRevision.label",
price: "itemRevision.price",
currency: "itemRevision.currency",
id: "item.id",
deviceId: "item.deviceId",
itemId: "item.catalogItemId",
categoryId: "item.categoryId",
createdAt: "item.createdAt",
label: "item.label",
price: "item.price",
currency: "item.currency",
categoryName: "category.name",
unitOfMeasure: "itemRevision.unitOfMeasure",
internalCode: "itemRevision.internalCode",
productCodeType: "itemRevision.productCodeType",
productCodeValue: "itemRevision.productCodeValue",
} as const satisfies Record<keyof ItemRevisionRow, string>;
unitOfMeasure: "item.unitOfMeasure",
internalCode: "item.internalCode",
productCodeType: "item.productCodeType",
productCodeValue: "item.productCodeValue",
} as const satisfies Record<keyof ItemRow, string>;

const createFilterableColumns = (t: TFunction) =>
[
Expand All @@ -254,7 +254,7 @@ const createFilterableColumns = (t: TFunction) =>
id: "productCodeValue",
title: t("items:detail.history.columns.productCode"),
},
] satisfies { id: keyof ItemRevisionRow; title: string }[];
] satisfies { id: keyof ItemRow; title: string }[];

export const ItemHistoryGrid = (props: { itemId: Id }) => {
const { t } = useTranslation();
Expand All @@ -263,26 +263,26 @@ export const ItemHistoryGrid = (props: { itemId: Id }) => {
() =>
createQuery((db) => {
return db
.selectFrom("item")
.leftJoin("category", "category.id", "item.categoryId")
.selectFrom("catalogItem")
.leftJoin("category", "category.id", "catalogItem.categoryId")
.select([
"item.id as id",
"item.deviceId as deviceId",
"item.categoryId as categoryId",
"item.label as label",
"item.price as price",
"item.currency as currency",
"item.unitOfMeasure as unitOfMeasure",
"item.internalCode as internalCode",
"item.productCodeType as productCodeType",
"item.productCodeValue as productCodeValue",
"catalogItem.id as id",
"catalogItem.deviceId as deviceId",
"catalogItem.categoryId as categoryId",
"catalogItem.label as label",
"catalogItem.price as price",
"catalogItem.currency as currency",
"catalogItem.unitOfMeasure as unitOfMeasure",
"catalogItem.internalCode as internalCode",
"catalogItem.productCodeType as productCodeType",
"catalogItem.productCodeValue as productCodeValue",
"category.name as categoryName",
] as const)
.where("item.isDeleted", "is not", sqliteTrue)
.where("item.id", "=", props.itemId)
.where("item.label", "is not", null)
.where("item.price", "is not", null)
.where("item.currency", "is not", null)
.where("catalogItem.isDeleted", "is not", sqliteTrue)
.where("catalogItem.id", "=", props.itemId)
.where("catalogItem.label", "is not", null)
.where("catalogItem.price", "is not", null)
.where("catalogItem.currency", "is not", null)
.$narrowType<{
label: KyselyNotNull;
price: KyselyNotNull;
Expand All @@ -301,7 +301,7 @@ export const ItemHistoryGrid = (props: { itemId: Id }) => {
);
const filterableColumns = useMemo(() => createFilterableColumns(t), [t]);

const onFilterChange = useMemo<DataTableOnFilterChange<ItemRevisionRow>>(
const onFilterChange = useMemo<DataTableOnFilterChange<ItemRow>>(
() =>
({ filters, sorting, setData, pagination: { limit, cursor } }) => {
const previousCursor =
Expand All @@ -317,28 +317,28 @@ export const ItemHistoryGrid = (props: { itemId: Id }) => {

const query = createQuery((db) => {
let qb = db
.selectFrom("itemRevision")
.leftJoin("category", "category.id", "itemRevision.categoryId")
.selectFrom("item")
.leftJoin("category", "category.id", "item.categoryId")
.select([
"itemRevision.id as id",
"itemRevision.deviceId as deviceId",
"itemRevision.itemId as itemId",
"itemRevision.categoryId as categoryId",
"itemRevision.createdAt as createdAt",
"itemRevision.label as label",
"itemRevision.price as price",
"itemRevision.currency as currency",
"itemRevision.unitOfMeasure as unitOfMeasure",
"itemRevision.internalCode as internalCode",
"itemRevision.productCodeType as productCodeType",
"itemRevision.productCodeValue as productCodeValue",
"item.id as id",
"item.deviceId as deviceId",
"item.catalogItemId as itemId",
"item.categoryId as categoryId",
"item.createdAt as createdAt",
"item.label as label",
"item.price as price",
"item.currency as currency",
"item.unitOfMeasure as unitOfMeasure",
"item.internalCode as internalCode",
"item.productCodeType as productCodeType",
"item.productCodeValue as productCodeValue",
"category.name as categoryName",
] as const)
.where("itemRevision.isDeleted", "is not", sqliteTrue)
.where("itemRevision.itemId", "=", props.itemId)
.where("itemRevision.label", "is not", null)
.where("itemRevision.price", "is not", null)
.where("itemRevision.currency", "is not", null)
.where("item.isDeleted", "is not", sqliteTrue)
.where("item.catalogItemId", "=", props.itemId)
.where("item.label", "is not", null)
.where("item.price", "is not", null)
.where("item.currency", "is not", null)
.$narrowType<{
label: KyselyNotNull;
price: KyselyNotNull;
Expand All @@ -355,20 +355,20 @@ export const ItemHistoryGrid = (props: { itemId: Id }) => {
),
eb.and([
eb(finalSorting.id, "=", previousCursor[finalSorting.id]),
eb("itemRevision.id", "<", previousCursor.id as Id),
eb("item.id", "<", previousCursor.id as Id),
]),
]),
);
}

qb = qb
.orderBy(finalSorting.id, finalSorting.desc ? "desc" : "asc")
.orderBy("itemRevision.id", "desc");
.orderBy("item.id", "desc");

for (const filter of filters) {
if (filter.id === "label") {
qb = qb.where(
"itemRevision.label",
"item.label",
"like",
`${filter.value}%` as NonEmptyString255,
);
Expand All @@ -382,14 +382,14 @@ export const ItemHistoryGrid = (props: { itemId: Id }) => {
}
if (filter.id === "internalCode") {
qb = qb.where(
"itemRevision.internalCode",
"item.internalCode",
"like",
`${filter.value}%` as NonEmptyString255,
);
}
if (filter.id === "productCodeValue") {
qb = qb.where(
"itemRevision.productCodeValue",
"item.productCodeValue",
"like",
`${filter.value}%` as NonEmptyString255,
);
Expand Down
36 changes: 18 additions & 18 deletions app/admin/(private)/catalog/detail/item-detail-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,39 @@ import { createQuery } from "@/lib/evolu";
export const createItemDetailQuery = (id: Id) =>
createQuery((db) => {
return db
.selectFrom("item")
.selectFrom("catalogItem")
.select(
(eb) =>
[
"item.id as id",
"item.deviceId as deviceId",
"item.label as label",
"item.price as price",
"item.currency as currency",
"item.unitOfMeasure as unitOfMeasure",
"item.categoryId as categoryId",
"item.productCodeType as productCodeType",
"item.productCodeValue as productCodeValue",
"item.internalCode as internalCode",
"item.createdAt as createdAt",
"item.updatedAt as updatedAt",
"catalogItem.id as id",
"catalogItem.deviceId as deviceId",
"catalogItem.label as label",
"catalogItem.price as price",
"catalogItem.currency as currency",
"catalogItem.unitOfMeasure as unitOfMeasure",
"catalogItem.categoryId as categoryId",
"catalogItem.productCodeType as productCodeType",
"catalogItem.productCodeValue as productCodeValue",
"catalogItem.internalCode as internalCode",
"catalogItem.createdAt as createdAt",
"catalogItem.updatedAt as updatedAt",

evoluJsonObjectFrom(
eb
.selectFrom("category")
.select(["category.name as name"])
.whereRef("category.id", "=", "item.categoryId")
.whereRef("category.id", "=", "catalogItem.categoryId")
.where("category.name", "is not", null)
.$narrowType<{
name: KyselyNotNull;
}>(),
).as("category"),
] as const,
)
.where("item.isDeleted", "is not", sqliteTrue)
.where("item.price", "is not", null)
.where("item.currency", "is not", null)
.where("item.id", "=", id)
.where("catalogItem.isDeleted", "is not", sqliteTrue)
.where("catalogItem.price", "is not", null)
.where("catalogItem.currency", "is not", null)
.where("catalogItem.id", "=", id)
.$narrowType<{
label: KyselyNotNull;
price: KyselyNotNull;
Expand Down
2 changes: 1 addition & 1 deletion app/admin/(private)/catalog/detail/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default function Layout(
return;
}

evolu.update("item", {
evolu.update("catalogItem", {
id: item.id,
isDeleted: sqliteTrue,
});
Expand Down
Loading
Loading