Skip to content

Commit

Permalink
sort untagged items by updated time
Browse files Browse the repository at this point in the history
  • Loading branch information
zetavg committed Jan 10, 2024
1 parent 9890ccc commit c6dda91
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ function RFIDUntaggedItemsScreen({
loading: rfidUntaggedItemsDataLoading,
refresh: refreshRfidUntaggedItems,
refreshing: rfidUntaggedItemsRefreshing,
} = useView('rfid_untagged_items', {
} = useView('rfid_untagged_items_by_updated_time', {
includeDocs: true,
descending: true,
});
const rfidUntaggedItems = rfidUntaggedItemsData
? rfidUntaggedItemsData
Expand All @@ -36,8 +37,9 @@ function RFIDUntaggedItemsScreen({
loading: rfidTagOutdatedItemsDataLoading,
refresh: refreshRfidTagOutdatedItems,
refreshing: rfidTagOutdatedItemsRefreshing,
} = useView('rfid_tag_outdated_items', {
} = useView('rfid_tag_outdated_items_by_updated_time', {
includeDocs: true,
descending: true,
});
const rfidTagOutdatedItems = rfidTagOutdatedItemsData
? rfidTagOutdatedItemsData
Expand Down
146 changes: 146 additions & 0 deletions packages/data-storage-couchdb/lib/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,78 @@ export const VIEWS = {
);
},
}),
rfid_untagged_items_by_updated_time: view_defn({
version: 1,
map: `
function (doc) {
if (
doc.type === 'item' &&
!!doc.data.rfid_tag_epc_memory_bank_contents &&
!doc.data.actual_rfid_tag_epc_memory_bank_contents
) {
emit([doc.updated_at], { _id: doc._id });
}
}
`,
dataParser: (data: unknown) => {
if (!data) return null;
if (typeof data !== 'object') return null;
const rows = (data as any).rows;
if (!Array.isArray(rows)) return null;
return rows.map(row =>
row.doc
? {
__data_included: true,
key: row.key,
id: row.id,
value: row.value,
data: getDatumFromDoc('item', row.doc),
}
: {
__data_included: false,
key: row.key,
id: row.id,
value: row.value,
},
);
},
}),
rfid_untagged_items_by_created_time: view_defn({
version: 1,
map: `
function (doc) {
if (
doc.type === 'item' &&
!!doc.data.rfid_tag_epc_memory_bank_contents &&
!doc.data.actual_rfid_tag_epc_memory_bank_contents
) {
emit([doc.created_at], { _id: doc._id });
}
}
`,
dataParser: (data: unknown) => {
if (!data) return null;
if (typeof data !== 'object') return null;
const rows = (data as any).rows;
if (!Array.isArray(rows)) return null;
return rows.map(row =>
row.doc
? {
__data_included: true,
key: row.key,
id: row.id,
value: row.value,
data: getDatumFromDoc('item', row.doc),
}
: {
__data_included: false,
key: row.key,
id: row.id,
value: row.value,
},
);
},
}),
rfid_tag_outdated_items_count: view_defn({
version: 1,
map: `
Expand Down Expand Up @@ -366,6 +438,80 @@ export const VIEWS = {
);
},
}),
rfid_tag_outdated_items_by_updated_time: view_defn({
version: 1,
map: `
function (doc) {
if (
doc.type === 'item' &&
!!doc.data.rfid_tag_epc_memory_bank_contents &&
!!doc.data.actual_rfid_tag_epc_memory_bank_contents &&
doc.data.rfid_tag_epc_memory_bank_contents !== doc.data.actual_rfid_tag_epc_memory_bank_contents
) {
emit([doc.updated_at], { _id: doc._id });
}
}
`,
dataParser: (data: unknown) => {
if (!data) return null;
if (typeof data !== 'object') return null;
const rows = (data as any).rows;
if (!Array.isArray(rows)) return null;
return rows.map(row =>
row.doc
? {
__data_included: true,
key: row.key,
id: row.id,
value: row.value,
data: getDatumFromDoc('item', row.doc),
}
: {
__data_included: false,
key: row.key,
id: row.id,
value: row.value,
},
);
},
}),
rfid_tag_outdated_items_by_created_time: view_defn({
version: 1,
map: `
function (doc) {
if (
doc.type === 'item' &&
!!doc.data.rfid_tag_epc_memory_bank_contents &&
!!doc.data.actual_rfid_tag_epc_memory_bank_contents &&
doc.data.rfid_tag_epc_memory_bank_contents !== doc.data.actual_rfid_tag_epc_memory_bank_contents
) {
emit([doc.created_at], { _id: doc._id });
}
}
`,
dataParser: (data: unknown) => {
if (!data) return null;
if (typeof data !== 'object') return null;
const rows = (data as any).rows;
if (!Array.isArray(rows)) return null;
return rows.map(row =>
row.doc
? {
__data_included: true,
key: row.key,
id: row.id,
value: row.value,
data: getDatumFromDoc('item', row.doc),
}
: {
__data_included: false,
key: row.key,
id: row.id,
value: row.value,
},
);
},
}),
purchase_price_sums: view_defn({
version: 1,
map: `
Expand Down

0 comments on commit c6dda91

Please sign in to comment.