2018-12-06 22:08:40 +00:00
|
|
|
/** @format */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { isNil } from 'lodash';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { getResourceName } from '../utils';
|
|
|
|
import { DEFAULT_REQUIREMENT } from '../constants';
|
|
|
|
|
|
|
|
const getNotes = ( getResource, requireResource ) => (
|
|
|
|
query = {},
|
|
|
|
requirement = DEFAULT_REQUIREMENT
|
|
|
|
) => {
|
|
|
|
const resourceName = getResourceName( 'note-query', query );
|
|
|
|
const ids = requireResource( requirement, resourceName ).data || [];
|
|
|
|
const notes = ids.map( id => getResource( getResourceName( 'note', id ) ).data || {} );
|
|
|
|
return notes;
|
|
|
|
};
|
|
|
|
|
2018-12-15 12:38:54 +00:00
|
|
|
const getNotesError = getResource => ( query = {} ) => {
|
|
|
|
const resourceName = getResourceName( 'note-query', query );
|
|
|
|
return getResource( resourceName ).error;
|
|
|
|
};
|
|
|
|
|
2018-12-06 22:08:40 +00:00
|
|
|
const isGetNotesRequesting = getResource => ( query = {} ) => {
|
|
|
|
const resourceName = getResourceName( 'note-query', query );
|
|
|
|
const { lastRequested, lastReceived } = getResource( resourceName );
|
|
|
|
|
2019-04-15 07:06:34 +00:00
|
|
|
if ( isNil( lastRequested ) || isNil( lastReceived ) ) {
|
2018-12-06 22:08:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lastRequested > lastReceived;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
getNotes,
|
2018-12-15 12:38:54 +00:00
|
|
|
getNotesError,
|
2018-12-06 22:08:40 +00:00
|
|
|
isGetNotesRequesting,
|
|
|
|
};
|