Smart relationship between model and stripe cards

Smart relationship between model and stripe cards

Context: as a user I want to display stripe cards associated to a user using the Stripe API.

Implementation

First step is to declare the smart collection user_stripe_cards in a user-stripe-cards.js file in the forest folder.

const { collection } = require('forest-express-sequelize');
const models = require('../models');

collection('users_stripe_cards', {
  isSearchable: true,
  fields: [
    {
      field: 'id',
      type: 'String',
    },
    {
      field: 'country',
      type: 'String',
    },
    {
      field: 'brand',
      type: 'String',
    },
    {
      field: 'exp_month',
      type: 'Number',
    },
    {
      field: 'exp_year',
      type: 'Number',
    },
    {
      field: 'last4',
      type: 'Number',
    },
  ],
});

Next step is to add the smart relationship between users and stripe cards in the forest/users.js file.

Final step is to implement the route for the relationship for the cards to be displayed as related data of a user. This is done in the routes/users.js file.

Last updated

Was this helpful?