0

I can't seem to find a proper way for my plugin to add a new field to existing collection types in Strapi.js.

What I need:

I need that upon install of the plugin a new field "votes" would be added to all the existing collection types. And endpoint would then be exposed to simply increase the numerical value of the "votes" by +1.

What I tried:

I tried creating a completely new, hidden collection called "votes", on POST request to a voting endpoint it would create a vote item with a reference to an existing collection item via uid and id. Then I would be able to count votes for an specific item by counting number of items in "votes" collection with a reference to the given item. This however seems like overengineering as in reality what I really need is to add a simple number to an item and then simply increase it by +1 everytime someone hits an endpoint.

1 Answers1

0

I handle this in the strapi.server file by adding more attributes to the content-type that I want to extend with the existence of my plugin.


export default {
  register: ({strapi}) => {
    strapi.contentTypes['plugin::users-permissions.user'].attributes['interests'] = {
      type: 'enumeration',
      enum: ['Music', 'Cooking', 'Sport'],
      attributes: {
        configurable: false,
        nullable: true
      }
    }    
  }