Skip to content

Instantly share code, notes, and snippets.

View Saad-ISAA's full-sized avatar

Saad Mujeeb Saad-ISAA

View GitHub Profile
@Saad-ISAA
Saad-ISAA / controller-mongo.js
Last active May 15, 2022 05:32
A Strapi controller to fetch data from MongoDB
'use strict';
const { createCoreController } = require('@strapi/strapi').factories;
const { find, findOne, insertOne } = require('../../../helper/mongo');
module.exports = createCoreController('api::reports.reports', ({ strapi }) => ({
async create(ctx) {
const data = ctx.request.body.data;
// create reports collection
'use strict';
const { connect } = require('./helper/mongo');
module.exports = {
/**
* An asynchronous register function that runs before
* your application is initialized.
*
* This gives you an opportunity to extend code.
*/
// eslint-disable-next-line @typescript-eslint/no-empty-function
// this is a helper utility class to help with mongodb queries and operations
// function to connect to mongodb and disconnect
const MongoClient = require('mongodb').MongoClient;
// change connect close to as required
// connect to mongodb on every call and connection details from env variables
const connect = async () => {
const client = await MongoClient.connect(process.env.MONGO_URL, {
useNewUrlParser: true,
@Saad-ISAA
Saad-ISAA / index-pubsub-strapi.js
Last active May 14, 2022 10:50
Strapi Bootsrap with Pub Sub config
'use strict';
const { psInit, psSubscribe, psPublish } = require('./helper/pubsub');
module.exports = {
/**
* An asynchronous register function that runs before
* your application is initialized.
*
* This gives you an opportunity to extend code.
*/
// eslint-disable-next-line @typescript-eslint/no-empty-function
@Saad-ISAA
Saad-ISAA / pubsub.js
Created May 14, 2022 06:39
GCP PubSub Helper Library
const { PubSub } = require('@google-cloud/pubsub');
function psInit() {
const projectId = process.env['GCP_PROJECT'];
// Instantiates a client
const pubsub = new PubSub({ projectId });
return pubsub;
}
async function psPublish(pubsub, topic, data) {
try {
@Saad-ISAA
Saad-ISAA / strapi-aws.js
Created July 10, 2021 04:25
Strapi with custom AWS S3 uploader for Large Files ~50GB
// File: aws/controllers/aws.js
const { S3Client, CreateMultipartUploadCommand, UploadPartCommand, ListPartsCommand,
CompleteMultipartUploadCommand } = require("@aws-sdk/client-s3");
const path = require("path");
const fs = require('fs');
const s3Client = new S3Client({ region: process.env.AWS_REGION });
module.exports = {