How to use the typeorm.getMongoRepository function in typeorm

To help you get started, we’ve selected a few typeorm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chnirt / nestjs-graphql-best-practice / src / resolvers / user.resolver.ts View on Github external
async verifyEmail(@Args('emailToken') emailToken: string): Promise {
		const user = await verifyEmailToken(emailToken)

		// console.log(user)

		if (!user.isVerified) {
			const updateUser = await getMongoRepository(User).save(
				new User({
					...user,
					isVerified: true,
				})
			)
			return updateUser ? true : false
		} else {
			throw new ForbiddenError('Your email has been verified.')
		}
	}
github chnirt / nestjs-graphql-best-practice / src / resolvers / user.resolver.ts View on Github external
async changePassword(
		@Args('_id') _id: string,
		@Args('currentPassword') currentPassword: string,
		@Args('password') password: string
	): Promise {
		const user = await getMongoRepository(User).findOne({ _id })

		// console.log(currentPassword , password)

		if (!user) {
			throw new ForbiddenError('User not found.')
		}

		if (!(await comparePassword(currentPassword, user.local.password))) {
			throw new ForbiddenError('Your current password is missing or incorrect.')
		}

		if (await comparePassword(password, user.local.password)) {
			throw new ForbiddenError(
				'Your new password must be different from your previous password.'
			)
		}
github chnirt / nestjs-graphql-best-practice / src / resolvers / user.resolver.ts View on Github external
async searchUser(@Args('userIds') userIds: string[]): Promise {
		let result

		if (userIds.length === 0) {
			throw new UserInputError('userIds can not be blank.')
		}

		result = await getMongoRepository(User).find({
			where: {
				_id: { $in: userIds }
			}
		})

		// tslint:disable-next-line:prefer-conditional-expression
		if (result.length > 1) {
			result = { users: result }
		} else {
			result = result[0]
		}

		return result
	}
github chnirt / nestjs-graphql-best-practice / src / resolvers / user.resolver.ts View on Github external
async createUser(
		@Args('input') input: CreateUserInput,
		@Context('pubsub') pubsub: any,
		@Context('req') req: any
	): Promise {
		try {
			const { email, password } = input

			let existedUser

			existedUser = await getMongoRepository(User).findOne({
				where: {
					'local.email': email
				}
			})

			if (existedUser) {
				throw new ForbiddenError('User already exists.')
			}

			// Is there a Google account with the same email?
			existedUser = await getMongoRepository(User).findOne({
				where: {
					$or: [{ 'google.email': email }, { 'facebook.email': email }]
				}
			})
github chnirt / nestjs-graphql-best-practice / src / resolvers / tree.resolver.ts View on Github external
async updateTree(
		@Args('input') input: string,
		@Args('_id') _id: string
	): Promise {
		try {
			const tree = await getMongoRepository(TreeEntity).findOne({ _id })
			if (!tree) {
				throw new ForbiddenError('Tree not found.')
			}
			const newTree = {
				...tree,
				treeData: input
			}
			const result = await getMongoRepository(TreeEntity).save(
				new TreeEntity({ ...newTree })
			)
			return true
		} catch (err) {
			throw new Error(err)
		}
	}
}
github chnirt / nestjs-graphql-best-practice / src / resolvers / company.resolver.ts View on Github external
async createCompany(
		@Args('input') input: CreateCompanyInput
	): Promise {
		const { name } = input

		const company = await getMongoRepository(Company).findOne({ name })

		if (company) {
			throw new ForbiddenError('Company already existed.')
		}

		return await getMongoRepository(Company).save(new Company({ ...input }))
	}
}
github chnirt / nestjs-graphql-best-practice / src / resolvers / room.resolver.ts View on Github external
_id,
		})

		if (!room) {
			throw new ForbiddenError('Room not found.')
		}

		const rs = room.users.filter(item => item._id === currentUser._id)

		if (rs.length === 0) {
			throw new ForbiddenError('You are not in the room.')
		}

		room.users = room.users.filter(item => item._id !== currentUser._id)

		return getMongoRepository(Room).save(room) ? true : false
	}
}
github chnirt / nestjs-graphql-best-practice / src / resolvers / role.resolver.ts View on Github external
async roles(): Promise {
		return getMongoRepository(Role).find({
			cache: true
		})
	}
github unix / koa-ts / app / services / sessions.service.ts View on Github external
constructor() {
    this.repository = getMongoRepository(Session)
  }
github chnirt / nestjs-graphql-best-practice / src / config / graphql / index.ts View on Github external
onDisconnect: async (webSocket, context) => {
					NODE_ENV !== 'production' &&
						Logger.error(`❌  Disconnected to websocket`, '', 'GraphQL', false)

					const { initPromise } = context
					const { currentUser } = await initPromise

					await getMongoRepository(User).updateOne(
						{ _id: currentUser._id },
						{
							$set: { isOnline: false },
						},
						{
							upsert: true,
						}
					)
				},
			},