Mirror of https://github.com/roostorg/coop github.com/roostorg/coop
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 557ff54b2b435e5f1e789c6a8a4e1bebf2d7deb6 48 lines 1.3 kB view raw
1import { DataSource } from 'apollo-datasource'; 2 3import { inject, type Dependencies } from '../../iocContainer/index.js'; 4import { type ItemSubmissionForGQL } from '../types.js'; 5 6export type UserHistoryForGQL = { 7 id: string; 8 user: ItemSubmissionForGQL; 9}; 10 11class InvestigationAPI extends DataSource { 12 constructor( 13 private readonly itemHistoryQueries: Dependencies['ItemHistoryQueries'], 14 ) { 15 super(); 16 } 17 18 async getItemHistory(opts: { 19 itemId: string; 20 itemTypeId: string; 21 orgId: string; 22 itemSubmissionTime?: Date; 23 }) { 24 const [startDate, endDate] = (() => { 25 if (!opts.itemSubmissionTime) { 26 return [undefined, undefined]; 27 } 28 29 const submissionTime = new Date(opts.itemSubmissionTime); 30 const startDate = new Date( 31 submissionTime.getFullYear(), 32 submissionTime.getMonth(), 33 submissionTime.getDate(), 34 ); 35 const endDate = new Date(startDate); 36 endDate.setDate(startDate.getDate() + 1); 37 38 return [startDate, endDate]; 39 })(); 40 return this.itemHistoryQueries.getItemRuleExecutionsHistory({ 41 ...opts, 42 filters: { startDate, endDate }, 43 }); 44 } 45} 46 47export default inject(['ItemHistoryQueries'], InvestigationAPI); 48export type { InvestigationAPI };