Commit 577f8a07 authored by velayat's avatar velayat
Browse files

404 error for search

parent 037349bd
import { import {
HttpException, HttpException,
Injectable, Injectable,
NotFoundException,
OnApplicationBootstrap, OnApplicationBootstrap,
} from '@nestjs/common'; } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose'; import { InjectModel } from '@nestjs/mongoose';
...@@ -9,6 +10,7 @@ import { CommentDocument } from './comment.schema'; ...@@ -9,6 +10,7 @@ import { CommentDocument } from './comment.schema';
import { IFollower } from './interface/Ifollower'; import { IFollower } from './interface/Ifollower';
import { IncomingComment } from './interface/IncomingComment'; import { IncomingComment } from './interface/IncomingComment';
import { RequestDocument } from './request.schema'; import { RequestDocument } from './request.schema';
const Instagram = require('instagram-web-api'); const Instagram = require('instagram-web-api');
const { username, password } = process.env; const { username, password } = process.env;
import * as _ from 'lodash'; import * as _ from 'lodash';
...@@ -22,6 +24,7 @@ import { LottoryResultDocument } from './LottoryResult.schema'; ...@@ -22,6 +24,7 @@ import { LottoryResultDocument } from './LottoryResult.schema';
@Injectable() @Injectable()
export class AppService implements OnApplicationBootstrap { export class AppService implements OnApplicationBootstrap {
client: any; client: any;
constructor( constructor(
@InjectModel('Request') @InjectModel('Request')
private requestModel: Model<RequestDocument>, private requestModel: Model<RequestDocument>,
...@@ -54,6 +57,7 @@ export class AppService implements OnApplicationBootstrap { ...@@ -54,6 +57,7 @@ export class AppService implements OnApplicationBootstrap {
console.log(err); console.log(err);
} }
} }
async getFollowers(account_username = 'azadi.gold') { async getFollowers(account_username = 'azadi.gold') {
try { try {
let hasNextPage = true; let hasNextPage = true;
...@@ -284,6 +288,7 @@ export class AppService implements OnApplicationBootstrap { ...@@ -284,6 +288,7 @@ export class AppService implements OnApplicationBootstrap {
throw new HttpException(err.message, 500); throw new HttpException(err.message, 500);
} }
} }
async sendFollowerRequest(client, username, cursor) { async sendFollowerRequest(client, username, cursor) {
try { try {
const Infollowers: IFollower[] = new Array<IFollower>(); const Infollowers: IFollower[] = new Array<IFollower>();
...@@ -322,6 +327,7 @@ export class AppService implements OnApplicationBootstrap { ...@@ -322,6 +327,7 @@ export class AppService implements OnApplicationBootstrap {
throw new HttpException(err.message, 500); throw new HttpException(err.message, 500);
} }
} }
async delay(ms) { async delay(ms) {
// return await for better async stack trace support in case of errors. // return await for better async stack trace support in case of errors.
console.log('delay time:', ms); console.log('delay time:', ms);
...@@ -585,10 +591,10 @@ export class AppService implements OnApplicationBootstrap { ...@@ -585,10 +591,10 @@ export class AppService implements OnApplicationBootstrap {
} }
async getUserResult(username: string) { async getUserResult(username: string) {
username = username.toLowerCase() username = username.toLowerCase();
const userRes = await this.resultModel.findOne({ username }); const userRes = await this.resultModel.findOne({ username });
const userIndexs = await this.lotoryResultModel.find({ username }); const userIndexs = await this.lotoryResultModel.find({ username });
if (!userRes) throw new NotFoundException('User not Found');
const response: ResultResponse = new ResultResponse(); const response: ResultResponse = new ResultResponse();
response.users = new Array<any>(); response.users = new Array<any>();
response.lottory_chances_codes = new Array<string>(); response.lottory_chances_codes = new Array<string>();
...@@ -669,7 +675,9 @@ export class AppService implements OnApplicationBootstrap { ...@@ -669,7 +675,9 @@ export class AppService implements OnApplicationBootstrap {
} }
async getResultDb() { async getResultDb() {
return await this.lotoryResultModel.find().select({username:1,index:1}); return await this.lotoryResultModel
.find()
.select({ username: 1, index: 1 });
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment