* WIP * WIP - MultiObjectSearch * WIP * WIP * Finished working version * Fix * Fixed and cleaned * Fix * Disabled files and emails for custom objects * Cleaned console.log * Fixed attachment * Fixed * fix lint --------- Co-authored-by: Charles Bochet <charles@twenty.com>
29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
import { Attachment } from '@/activities/files/types/Attachment';
|
|
import { ActivityTargetableObject } from '@/activities/types/ActivityTargetableEntity';
|
|
import { getActivityTargetObjectFieldIdName } from '@/activities/utils/getTargetObjectFilterFieldName';
|
|
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
|
|
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
|
|
|
|
// do we need to test this?
|
|
export const useAttachments = (targetableObject: ActivityTargetableObject) => {
|
|
const targetableObjectFieldIdName = getActivityTargetObjectFieldIdName({
|
|
nameSingular: targetableObject.targetObjectNameSingular,
|
|
});
|
|
|
|
const { records: attachments } = useFindManyRecords({
|
|
objectNameSingular: CoreObjectNameSingular.Attachment,
|
|
filter: {
|
|
[targetableObjectFieldIdName]: {
|
|
eq: targetableObject.id,
|
|
},
|
|
},
|
|
orderBy: {
|
|
createdAt: 'DescNullsFirst',
|
|
},
|
|
});
|
|
|
|
return {
|
|
attachments: attachments as Attachment[],
|
|
};
|
|
};
|