Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { Injectable, Inject } from '@graphql-modules/di';
import { MentorEntity } from './mentor-entity';
import { TableService, TableQuery } from 'azure-storage';
export interface IMentorRepository {
getMentees(mentorId: string): Promise;
addMentee(mentor: MentorEntity): Promise;
tableName: string;
}
@Injectable()
class MentorRepository implements IMentorRepository {
public tableName: string = 'mentorentity';
constructor(@Inject('TableService') private tableService: TableService) {
this.tableService.doesTableExist(this.tableName, (error, result) => {
if (!result.exists) {
this.tableService.createTable(this.tableName, (error, result) => {
console.log(error);
console.log(result);
});
}
});
}
public async getMentees(mentorId: string): Promise {
return new Promise((resolve, reject) => {
constructor(@Inject('TableService') private tableService: TableService) {
this.tableService.doesTableExist(this.tableName, (error, result) => {
if (!result.exists) {
this.tableService.createTable(this.tableName, (error, result) => {
console.log(error);
console.log(result);
});
}
});
}
constructor(@Inject('TableService') private tableService: TableService) {
this.tableService.doesTableExist(this.tableName, (error, result) => {
if (!result.exists) {
this.tableService.createTable(this.tableName, (error, result) => {
console.log(error);
console.log(result);
});
}
});
}
addMentor(mentee: MenteeEntity): Promise {
import { Injectable, ProviderScope } from '@graphql-modules/di';
import dataloader from 'dataloader';
import nodeFetch, { Response } from 'node-fetch';
import { Products, Product } from '../../../_graphql';
import { checkStatus } from '../../../helpers';
import { CREDENTIALS, BOL_API } from '../../../constants';
import { productDataLoader } from './product-data-loader';
@Injectable({
scope: ProviderScope.Session,
})
export class ProductProvider {
private dataLoaderProduct: any;
constructor() {
this.dataLoaderProduct = new dataloader(keys =>
productDataLoader(keys),
);
}
/**
* Example 1: not dataloader used while it should
*/
public async getProducts(id: string): Promise {
const url = `${BOL_API}/lists/?ids=${id}&limit=12&format=json&${CREDENTIALS}`;
console.log(`[BAD] no dataloader: ${url.slice(0, -40)}`);
import { Injectable } from '@graphql-modules/di'
import { PubSub } from 'apollo-server-express'
import { Connection } from 'typeorm'
import { User } from '../../../entity/User';
import { Chat } from '../../../entity/Chat';
import { ChatProvider } from '../../chat/providers/chat.provider';
import { Message } from '../../../entity/Message';
import { MessageType } from '../../../db';
import { AuthProvider } from '../../auth/providers/auth.provider';
import { UserProvider } from '../../user/providers/user.provider';
@Injectable()
export class MessageProvider {
constructor(
private pubsub: PubSub,
private connection: Connection,
private chatProvider: ChatProvider,
private authProvider: AuthProvider,
private userProvider: UserProvider,
) { }
repository = this.connection.getRepository(Message);
currentUser = this.authProvider.currentUser;
createQueryBuilder() {
return this.connection.createQueryBuilder(Message, 'message');
}
import { Injectable } from '@graphql-modules/di'
import { PubSub } from 'apollo-server-express'
import { Connection } from 'typeorm'
import { User } from '../../../entity/User';
import { Chat } from '../../../entity/Chat';
import { UserProvider } from '../../user/providers/user.provider';
import { AuthProvider } from '../../auth/providers/auth.provider';
@Injectable()
export class ChatProvider {
constructor(
private pubsub: PubSub,
private connection: Connection,
private userProvider: UserProvider,
private authProvider: AuthProvider,
) {
}
repository = this.connection.getRepository(Chat);
currentUser = this.authProvider.currentUser;
createQueryBuilder() {
return this.connection.createQueryBuilder(Chat, 'chat');
}
import 'reflect-metadata';
import { Inject, Injectable } from '@graphql-modules/di';
import { Context, HttpRequest } from '@azure/functions';
import { IMentorRepository } from '@repositories/mentor-repository/mentor-repository';
@Injectable()
class GetMentees {
constructor(
@Inject('IMentorRepository') private mentorRepository: IMentorRepository
) {}
index = async (context: Context, req: HttpRequest): Promise => {
context.log('JavaScript HTTP trigger function processed a request.');
const mentorId = req.query.mentorId;
const mentees = await this.mentorRepository.getMentees(mentorId);
context.res = {
status: '200',
body: JSON.stringify(mentees),
};
};
}
import { Inject, Injectable } from '@graphql-modules/di';
import { ChatDbObject, MessageDbObject } from "@models";
import { CHATS, MESSAGES } from "@modules/common";
@Injectable()
export class MessagesProvider {
constructor(
@Inject(MESSAGES) private messages: MessageDbObject[],
@Inject(CHATS) private chats: ChatDbObject[],
) {}
getMessages(chatId: number): MessageDbObject[] {
return this.messages.filter(message => message.chatId === chatId);
}
getMessage(id: number): MessageDbObject {
return this.messages.find(message => message.id === id);
}
createMessage(content: string, chatId: number): MessageDbObject {
authorId: 0,
title: 'Title 1',
},
{
_id: 1,
authorId: 1,
title: 'Title 2',
},
{
_id: 2,
authorId: 0,
title: 'Title 3',
},
];
@Injectable()
export class Blog {
constructor(
private users: Users,
) {}
getPostsOf(userId: number) {
return posts.filter(({ authorId }) => userId === authorId);
}
allPosts() {
return posts;
}
getAuthor(postId: number) {
const post = posts.find(({ _id }) => _id === postId);
import { Injectable, Inject, ProviderScope } from '@graphql-modules/di';
import sql from 'sql-template-strings';
import bcrypt from 'bcrypt';
import { Database } from '../common/database.provider';
const DEFAULT_PROFILE_PIC = 'https://raw.githubusercontent.com/Urigo/WhatsApp-Clone-Client-React/legacy/public/assets/default-profile-pic.jpg'
@Injectable({
scope: ProviderScope.Session,
})
export class Users {
@Inject() private db: Database;
async findById(userId: string) {
const db = await this.db.getClient();
const { rows } = await db.query(
sql`SELECT * FROM users WHERE id = ${userId}`
);
return rows[0] || null;
}
async findAllExcept(userId: string) {
const db = await this.db.getClient();