grupoboticario / nestjs-sap-rfc

NestJS SAP RFC Client, providing convenient ABAP business logic consumption from Nest.
MIT License
13 stars 2 forks source link

how to populate clientOptions #974

Closed russosalv closed 10 months ago

russosalv commented 1 year ago

hi i have soem issue poplating

clientOptions

as per SAPRfc doc https://github.com/SAP/node-rfc/blob/main/doc/usage.md#date-and-time-conversion-options-date-and-time

for date and time need to populate as follow :

date: {
        // Node.js Date() to ABAP YYYYMMDD
        toABAP: function (date) {
            if (!(date instanceof Date))
                return new TypeError(`Date object required: ${date}`);
            let mm = date.getMonth() + 1;
            let dd = date.getUTCDate();
            return [
                date.getFullYear(),
                mm > 9 ? mm : "0" + mm,
                dd > 9 ? dd : "0" + dd,
            ].join("");
        },

        fromABAP: function (dats) {
            // ABAP YYYYMMDD to Node.js Date()
            return new Date(
                0 | dats.substring(0, 4),
                (0 | dats.substring(4, 6)) - 1,
                (0 | dats.substring(6, 8)) + 1
            );
        },
    },

but if i tried to add in app.module i have exception that this declaration is not correct because date: is function

how fix it?

alvarolimajr commented 10 months ago

Hi @russosalv, Now you can use date conversion as desired, just update the nestjs-sap-rfc lib to version 4.x (4.0 currently). In this new release we updated to the latest version of node-rfc that corrected this property. Additionally, we introduced the option to execute RFCs in a transaction. Let me know if you need anything else. Take the opportunity to test and give us feedback.

See the example below:

@Module({
  imports: [
    SapModule.createPool({
      isGlobal: true, // for global module
      name: 'service_name', // for multiple modules (OPTIONAL)
      connectionParameters: {
        /* see RfcConnectionParameters */
      },
      clientOptions: {
        date: {
          // Node.js Date() to ABAP YYYYMMDD
          toABAP: function (date) {
            if (!(date instanceof Date)) {
              return new TypeError(`Date object required: ${date}`);
            }

            const mm = date.getMonth() + 1;
            const dd = date.getUTCDate();

            return [
              date.getFullYear(),
              mm > 9 ? mm : '0' + mm,
              dd > 9 ? dd : '0' + dd,
            ].join('');
          },

          fromABAP: function (dats) {
            // ABAP YYYYMMDD to Node.js Date()
            return new Date(
              0 | dats.substring(0, 4),
              (0 | dats.substring(4, 6)) - 1,
              (0 | dats.substring(6, 8)) + 1,
            );
          },
        },
      },
      poolOptions: {
        /* see RfcPoolOptions */
      },
    }),
  ],
})
export class AppModule {}

Thank you very much for getting in touch.