You can follow this approach to create custom api in Strapi. Use the linked example and append it with your custom logic.