|
|
|
|
@ -1,13 +1,16 @@
|
|
|
|
|
import { BadRequestException, Body, Controller, Get, Post } from '@nestjs/common';
|
|
|
|
|
import { BadRequestException, Body, Controller, Get, Post, Query, Req } from '@nestjs/common';
|
|
|
|
|
import { AppService } from './app.service';
|
|
|
|
|
import * as fs from 'fs';
|
|
|
|
|
import { ApiProperty } from '@nestjs/swagger';
|
|
|
|
|
import { IsArray, IsBoolean, IsDateString, IsNotEmpty, IsString } from 'class-validator';
|
|
|
|
|
import { ApiBearerAuth, ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
|
|
|
import { IsArray, IsBoolean, IsDateString, IsNotEmpty, IsOptional, IsString } from 'class-validator';
|
|
|
|
|
import { NodeVisitorEntity } from './node-visitor.entity';
|
|
|
|
|
import { DataSource } from 'typeorm';
|
|
|
|
|
import { DataSource, Repository } from 'typeorm';
|
|
|
|
|
import * as bluebird from 'bluebird';
|
|
|
|
|
import { NodeOtherVisitorEntity } from './node-other-visitor.entity';
|
|
|
|
|
import * as moment from 'moment';
|
|
|
|
|
import { CommonPageArgs } from './common';
|
|
|
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
|
|
|
|
|
export class Electronics {
|
|
|
|
|
@ApiProperty({ description: "电子产品名称" })
|
|
|
|
|
@ -133,12 +136,27 @@ export class CreateVisitor {
|
|
|
|
|
public may_access_sensitive_info: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class QueryVisitorDto extends CommonPageArgs {
|
|
|
|
|
// @ApiPropertyOptional({ description: '真实姓名' })
|
|
|
|
|
// @IsString()
|
|
|
|
|
// @IsOptional()
|
|
|
|
|
// true_name: string
|
|
|
|
|
|
|
|
|
|
@ApiPropertyOptional({ description: "根据名称模糊搜索", required: false })
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsOptional()
|
|
|
|
|
search?: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Controller()
|
|
|
|
|
export class AppController {
|
|
|
|
|
constructor(
|
|
|
|
|
private readonly appService: AppService,
|
|
|
|
|
|
|
|
|
|
private readonly dataSource: DataSource,
|
|
|
|
|
@InjectRepository(NodeVisitorEntity)
|
|
|
|
|
private readonly nodeVisitorRepository: Repository<NodeVisitorEntity>,
|
|
|
|
|
@InjectRepository(NodeOtherVisitorEntity)
|
|
|
|
|
private readonly nodeOtherVisitorRepository: Repository<NodeOtherVisitorEntity>,
|
|
|
|
|
) { }
|
|
|
|
|
|
|
|
|
|
@Get()
|
|
|
|
|
@ -166,6 +184,44 @@ export class AppController {
|
|
|
|
|
// return "n9zX2u8E9ShFgYmx";
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
@Get("/visitors")
|
|
|
|
|
@ApiBearerAuth()
|
|
|
|
|
async get(@Query() query: QueryVisitorDto, @Req() req: any) {
|
|
|
|
|
console.log("req", req.headers)
|
|
|
|
|
if (!req.headers.authorization) {
|
|
|
|
|
throw new BadRequestException("无权限")
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
// console.log(`${process.env.RUST_URI}/api/viewer`)
|
|
|
|
|
const result = await axios.get(`${process.env.RUST_URI}/api/viewer`, {
|
|
|
|
|
headers: {
|
|
|
|
|
authorization: req.headers.authorization
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
// console.log("result", result)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// console.log(e)
|
|
|
|
|
throw new BadRequestException("无权限, 请联系管理员")
|
|
|
|
|
}
|
|
|
|
|
const [list, count] = await this.nodeVisitorRepository.findAndCount({
|
|
|
|
|
skip: query.skip,
|
|
|
|
|
take: query.take,
|
|
|
|
|
order: {
|
|
|
|
|
created_date: "DESC"
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
const new_list = await bluebird.map(list, async (item) => {
|
|
|
|
|
const visitor_list = await this.nodeOtherVisitorRepository.find({
|
|
|
|
|
where: { node_visitor_id: item.id }
|
|
|
|
|
})
|
|
|
|
|
return {
|
|
|
|
|
...item,
|
|
|
|
|
visitor_list
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
return { list: new_list, count }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post("/visitor")
|
|
|
|
|
async create(@Body() data: CreateVisitor) {
|
|
|
|
|
if (new Date(data.apply_date).toString() == "Invalid Date") {
|
|
|
|
|
@ -210,6 +266,7 @@ export class AppController {
|
|
|
|
|
new_node_other_visitor.identity_card_no = item.identity_card_no;
|
|
|
|
|
new_node_other_visitor.nationality_type = item.nationality_type;
|
|
|
|
|
new_node_other_visitor.nationality = item.nationality;
|
|
|
|
|
new_node_other_visitor.node_visitor_id = result.id;
|
|
|
|
|
await transactionalEntityManager.save(new_node_other_visitor);
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|