Skip to content

getPaginationInfo Error in strapi-plugin-fcm #28

@alihassan1221

Description

@alihassan1221

I am unable to retrieve topics/targets for custom notifications from the admin dashboard using the Strapi FCM plugin. When attempting to navigate to the notifications section, I encounter the following error:

error: getPaginationInfo is not a function
TypeError: getPaginationInfo is not a function
at Object.find (/Users/Desktop/latest-pfbackend/node_modules/strapi-plugin-fcm/server/services/fcm-target.js:56:32)
at Object.find (/Users/Desktop/latest-pfbackend/node_modules/strapi-plugin-fcm/server/controllers/fcm-target.js:14:43)
at dispatch (/Users/Desktop/latest-pfbackend/node_modules/koa-compose/index.js:42:32)
at returnBodyMiddleware (/Users/Desktop/latest-pfbackend/node_modules/@strapi/strapi/lib/services/server/compose-endpoint.js:52:24)
at dispatch (/Users/Desktop/latest-pfbackend/node_modules/koa-compose/index.js:42:32)
at policiesMiddleware (/Users/Desktop/latest-pfbackend/node_modules/@strapi/strapi/lib/services/server/policy.js:24:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Screenshot 2024-10-01 at 2 38 11 PM

No targets found.
Add topics to 'FCM Topic' Collection, and optionally configure which collection contains the devices tokens.

node_modules/strapi-plugin-fcm/server/services/fcm-target.js:

`'use strict';

const {
getPaginationInfo,
convertPagedToStartLimit,
shouldCount,
transformPaginationResponse,
} = require('@strapi/strapi');

const { getFetchParams } = require('@strapi/strapi/lib/core-api/service');

// we will use this for now, until we have a better way.
const getQuery = (
devicesTokensCollectionName,
deviceTokenFieldName,
deviceLabelFieldName,
offset = 0,
limit = 25
) => {
if (!devicesTokensCollectionName) {
return select fcm_topics.name as label, 'topic' as type, fcm_topics.name as value from fcm_topics limit ${limit} offset ${offset};
}
return (select fcm_topics.label as label, 'topic' as type, fcm_topics.name as value from fcm_topics) union all (select ${devicesTokensCollectionName}.${deviceLabelFieldName} as label, 'token' as type, ${devicesTokensCollectionName}.${deviceTokenFieldName} as value from ${devicesTokensCollectionName} where coalesce(TRIM(${devicesTokensCollectionName}.${deviceTokenFieldName}), '') <> '') limit ${limit} offset ${offset};

};

const countQuery = (
devicesTokensCollectionName,
deviceTokenFieldName
) => {
if (!devicesTokensCollectionName) {
return select count(*) as count from fcm_topics;
}
return select count(*) from ((select fcm_topics.name as value from fcm_topics) union all (select ${devicesTokensCollectionName}.${deviceTokenFieldName} as value from ${devicesTokensCollectionName} where coalesce(TRIM(${devicesTokensCollectionName}.${deviceTokenFieldName}), '') <> '')) as targets; ;
};

const getConfigurationService = () => {
return strapi.plugin('strapi-plugin-fcm').service('fcm-plugin-configuration');
}

module.exports = ({ strapi }) => ({

async find(params = {}) {
    const fetchParams = getFetchParams(params);
    const paginationInfo = getPaginationInfo(fetchParams);
    const startLimit = convertPagedToStartLimit(paginationInfo);
    // console.log('startLimit', startLimit, 'paginationInfo', paginationInfo);

    const knex = strapi.db.connection;

    const configs = (await getConfigurationService().find()).data;
    // console.log('fcm-target configs', configs);

    const devicesTokensCollectionName = configs.devicesTokensCollectionName;
    const deviceTokenFieldName = configs.deviceTokenFieldName;
    const deviceLabelFieldName = configs.deviceLabelFieldName;

    const results = await knex.raw(
        getQuery(devicesTokensCollectionName,
            deviceTokenFieldName,
            deviceLabelFieldName,
            startLimit.start || 0,
            startLimit.limit || 25)
    );
    let rows
    switch (knex.client.config.client) {
        case 'better-sqlite3': {
            rows = results
            break;
        }
        default: {
            rows = results.rows || results[0];
            break;
        }
    }
    // console.log('fcm-target results', rows);
    if (shouldCount(fetchParams)) {
        const countResult = await knex.raw(countQuery(devicesTokensCollectionName, deviceTokenFieldName, deviceLabelFieldName));
        const count = (countResult.rows || countResult[0])?.[0]?.count;
        // console.log('fcm-target countResult', count);
        return {
            data: rows,
            pagination: transformPaginationResponse(paginationInfo, Number(count)),
        };
    }

    return {
        data: rows,
        pagination: paginationInfo,
    };

},
count(params = {}) {
    const knex = strapi.db.connection;
    return knex.raw(countQuery('fcm_tokens', 'token', 'label'));
},

});
`

Steps to Reproduce

  • Navigate to the strapi-plugin-fcm section in the Strapi admin dashboard.
  • Attempt to view or send custom notifications.
  • Observe the error in the console.

Expected Behavior
I expect to see the list of available topics and device tokens for sending notifications, as well as functional pagination controls to navigate through the results.

Environment
Strapi Version: 4.12.6 (node v18.20.0)
Strapi Plugin FCM Version: "^1.1.0"
Database: postgres

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions