builds backend initated
This commit is contained in:
@@ -6,7 +6,7 @@ import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
import { UsersModule } from './users/users.module';
|
||||
import { PeopleModule } from './people/people.module';
|
||||
import { BuildModule } from './build/build.module';
|
||||
import { BuildModule } from './builds/build.module';
|
||||
import { BuildPartsModule } from './build-parts/build-parts.module';
|
||||
import { BuildAreaModule } from './build-area/build-area.module';
|
||||
import { UserTypesModule } from './user-types/user-types.module';
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { ExpiryBaseInput } from "@/models/base.model";
|
||||
import { InputType, Field } from "@nestjs/graphql";
|
||||
|
||||
@InputType()
|
||||
export class UpdateBuildIbanInput {
|
||||
export class UpdateBuildIbanInput extends ExpiryBaseInput {
|
||||
|
||||
@Field({ nullable: true })
|
||||
iban?: string;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { InputType, Field } from '@nestjs/graphql';
|
||||
import { InputType, Field, ID } from '@nestjs/graphql';
|
||||
|
||||
|
||||
@InputType()
|
||||
export class CreateBuildPartsInput {
|
||||
|
||||
@Field()
|
||||
uuid: string;
|
||||
@Field(() => ID)
|
||||
build: string;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { ObjectType, Field } from "@nestjs/graphql";
|
||||
import { BuildSites } from "@/models/build-site.model";
|
||||
|
||||
|
||||
@ObjectType()
|
||||
export class ListBuildSitesResponse {
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
import { Resolver, Query, Args, ID, Info, Mutation } from '@nestjs/graphql';
|
||||
import { Types } from 'mongoose';
|
||||
import { Build } from '@/models/build.model';
|
||||
import { CreateBuildInput } from './dto/create-build.input';
|
||||
import graphqlFields from 'graphql-fields';
|
||||
import { BuildService } from './build.service';
|
||||
import type { GraphQLResolveInfo } from 'graphql';
|
||||
|
||||
@Resolver()
|
||||
export class BuildResolver {
|
||||
|
||||
constructor(private readonly buildService: BuildService) { }
|
||||
|
||||
@Query(() => [Build], { name: 'Builds' })
|
||||
async getBuilds(@Info() info: GraphQLResolveInfo): Promise<Build[]> {
|
||||
const fields = graphqlFields(info); const projection = this.buildService.buildProjection(fields); return this.buildService.findAll(projection);
|
||||
}
|
||||
|
||||
@Query(() => Build, { name: 'Build', nullable: true })
|
||||
async getBuild(@Args('id', { type: () => ID }) id: string, @Info() info: GraphQLResolveInfo): Promise<Build | null> {
|
||||
const fields = graphqlFields(info); const projection = this.buildService.buildProjection(fields); return this.buildService.findById(new Types.ObjectId(id), projection);
|
||||
}
|
||||
|
||||
@Mutation(() => Build, { name: 'createBuild' })
|
||||
async createBuild(@Args('input') input: CreateBuildInput): Promise<Build> {
|
||||
return this.buildService.create(input);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Types, Model } from 'mongoose';
|
||||
import { Build, BuildDocument } from '@/models/build.model';
|
||||
import { CreateBuildInput } from './dto/create-build.input';
|
||||
|
||||
@Injectable()
|
||||
export class BuildService {
|
||||
|
||||
constructor(@InjectModel(Build.name) private readonly buildModel: Model<BuildDocument>) { }
|
||||
|
||||
async findAll(projection?: any): Promise<BuildDocument[]> {
|
||||
return this.buildModel.find({}, projection, { lean: false }).populate({ path: 'buildArea', select: projection?.buildArea }).exec();
|
||||
}
|
||||
|
||||
async findById(id: Types.ObjectId, projection?: any): Promise<BuildDocument | null> {
|
||||
return this.buildModel.findById(id, projection, { lean: false }).populate({ path: 'buildArea', select: projection?.buildArea }).exec();
|
||||
}
|
||||
|
||||
async create(input: CreateBuildInput): Promise<BuildDocument> { const buildArea = new this.buildModel(input); return buildArea.save() }
|
||||
|
||||
buildProjection(fields: Record<string, any>): any {
|
||||
const projection: any = {};
|
||||
for (const key in fields) {
|
||||
if (key === 'buildArea' && typeof fields[key] === 'object') { for (const subField of Object.keys(fields[key])) { projection[`buildArea.${subField}`] = 1 } }
|
||||
else { projection[key] = 1 }
|
||||
}
|
||||
return projection;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
import { InputType, Field } from "@nestjs/graphql";
|
||||
|
||||
@InputType()
|
||||
export class UpdateBuildAttributeInput {
|
||||
|
||||
@Field({ nullable: true })
|
||||
buildType?: string;
|
||||
|
||||
@Field({ nullable: true })
|
||||
site?: string;
|
||||
|
||||
@Field({ nullable: true })
|
||||
address?: string;
|
||||
|
||||
@Field({ nullable: true })
|
||||
areas?: string[];
|
||||
|
||||
}
|
||||
|
||||
@InputType()
|
||||
export class UpdateBuildResponsibleInput {
|
||||
|
||||
@Field({ nullable: true })
|
||||
company?: string;
|
||||
|
||||
@Field({ nullable: true })
|
||||
person?: string;
|
||||
|
||||
}
|
||||
40
backend/src/builds/build.resolver.ts
Normal file
40
backend/src/builds/build.resolver.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Resolver, Query, Args, ID, Info, Mutation } from '@nestjs/graphql';
|
||||
import { Types } from 'mongoose';
|
||||
import { Build } from '@/models/build.model';
|
||||
import { CreateBuildInput } from './dto/create-build.input';
|
||||
import { UpdateBuildResponsibleInput, UpdateBuildAttributeInput } from './dto/update-build.input';
|
||||
import graphqlFields from 'graphql-fields';
|
||||
import { BuildService } from './build.service';
|
||||
import type { GraphQLResolveInfo } from 'graphql';
|
||||
import { ListArguments } from '@/dto/list.input';
|
||||
import { ListBuildResponse } from './dto/list-build.response';
|
||||
|
||||
@Resolver()
|
||||
export class BuildResolver {
|
||||
|
||||
constructor(private readonly buildService: BuildService) { }
|
||||
|
||||
@Query(() => ListBuildResponse, { name: 'builds' })
|
||||
async getBuilds(@Info() info: GraphQLResolveInfo, @Args('input') input: ListArguments): Promise<ListBuildResponse> {
|
||||
const fields = graphqlFields(info); const projection = this.buildService.buildProjection(fields); return this.buildService.findAll(projection, input.skip, input.limit, input.sort, input.filters);
|
||||
}
|
||||
|
||||
@Query(() => Build, { name: 'build', nullable: true })
|
||||
async getBuild(@Args('id', { type: () => ID }) id: string, @Info() info: GraphQLResolveInfo): Promise<Build | null> {
|
||||
const fields = graphqlFields(info); const projection = this.buildService.buildProjection(fields); return this.buildService.findById(new Types.ObjectId(id), projection);
|
||||
}
|
||||
|
||||
@Mutation(() => Build, { name: 'createBuild' })
|
||||
async createBuild(@Args('input') input: CreateBuildInput): Promise<Build> { return this.buildService.create(input) }
|
||||
|
||||
@Mutation(() => Build, { name: 'updateBuildResponsible' })
|
||||
async updateBuildResponsible(@Args('uuid', { type: () => ID }) uuid: string, @Args('input') input: UpdateBuildResponsibleInput): Promise<Build> {
|
||||
return this.buildService.updateResponsible(uuid, input);
|
||||
}
|
||||
|
||||
@Mutation(() => Build, { name: 'updateBuildAttribute' })
|
||||
async updateBuildAttribute(@Args('uuid', { type: () => ID }) uuid: string, @Args('input') input: UpdateBuildAttributeInput): Promise<Build> {
|
||||
return this.buildService.updateAttribute(uuid, input);
|
||||
}
|
||||
|
||||
}
|
||||
44
backend/src/builds/build.service.ts
Normal file
44
backend/src/builds/build.service.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Types, Model } from 'mongoose';
|
||||
import { Build, BuildDocument } from '@/models/build.model';
|
||||
import { CreateBuildInput } from './dto/create-build.input';
|
||||
import { UpdateBuildAttributeInput, UpdateBuildResponsibleInput } from './dto/update-build.input';
|
||||
import { ListBuildResponse } from './dto/list-build.response';
|
||||
|
||||
@Injectable()
|
||||
export class BuildService {
|
||||
|
||||
constructor(@InjectModel(Build.name) private readonly buildModel: Model<BuildDocument>) { }
|
||||
|
||||
async findAll(projection: any, skip: number, limit: number, sort?: Record<string, 1 | -1>, filters?: Record<string, any>): Promise<ListBuildResponse> {
|
||||
const query: any = {}; if (filters && Object.keys(filters).length > 0) { Object.assign(query, filters) };
|
||||
const totalCount = await this.buildModel.countDocuments(query).exec();
|
||||
const data = await this.buildModel.find(query).skip(skip).limit(limit).sort(sort).exec();
|
||||
return { data, totalCount };
|
||||
}
|
||||
|
||||
async findById(id: Types.ObjectId, projection?: any): Promise<BuildDocument | null> {
|
||||
return this.buildModel.findById(id, projection, { lean: false }).populate({ path: 'buildArea', select: projection?.buildArea }).exec();
|
||||
}
|
||||
|
||||
async create(input: CreateBuildInput): Promise<BuildDocument> { const buildArea = new this.buildModel(input); return buildArea.save() }
|
||||
|
||||
async updateResponsible(uuid: string, input: UpdateBuildResponsibleInput): Promise<BuildDocument> {
|
||||
const build = await this.buildModel.findOne({ uuid }); if (!build) { throw new Error('Build not found') }; build.set({ responsible: input }); return build.save()
|
||||
}
|
||||
|
||||
async updateAttribute(uuid: string, input: UpdateBuildAttributeInput): Promise<BuildDocument> {
|
||||
const build = await this.buildModel.findOne({ uuid }); if (!build) { throw new Error('Build not found') }; build.set({ attribute: input }); return build.save()
|
||||
}
|
||||
|
||||
buildProjection(fields: Record<string, any>): any {
|
||||
const projection: any = {};
|
||||
for (const key in fields) {
|
||||
if (key === 'build' && typeof fields[key] === 'object') { for (const subField of Object.keys(fields[key])) { projection[`build.${subField}`] = 1 } }
|
||||
else { projection[key] = 1 }
|
||||
}
|
||||
return projection;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { ExpiryBaseInput } from "@/models/base.model";
|
||||
import { InputType, Field, ID } from "@nestjs/graphql";
|
||||
|
||||
@InputType()
|
||||
@@ -54,7 +55,7 @@ export class CreateBuildInfoInput {
|
||||
}
|
||||
|
||||
@InputType()
|
||||
export class CreateBuildInput {
|
||||
export class CreateBuildInput extends ExpiryBaseInput {
|
||||
|
||||
@Field(() => ID)
|
||||
buildType: string;
|
||||
13
backend/src/builds/dto/list-build.response.ts
Normal file
13
backend/src/builds/dto/list-build.response.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Build } from "@/models/build.model";
|
||||
import { Field, Int, ObjectType } from "@nestjs/graphql";
|
||||
|
||||
@ObjectType()
|
||||
export class ListBuildResponse {
|
||||
|
||||
@Field(() => [Build], { nullable: true })
|
||||
data?: Build[];
|
||||
|
||||
@Field(() => Int, { nullable: true })
|
||||
totalCount?: number;
|
||||
|
||||
}
|
||||
43
backend/src/builds/dto/update-build.input.ts
Normal file
43
backend/src/builds/dto/update-build.input.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { InputType, Field, ID } from "@nestjs/graphql";
|
||||
|
||||
@InputType()
|
||||
export class UpdateResponsibleInput {
|
||||
|
||||
@Field(() => ID, { nullable: true })
|
||||
company?: string;
|
||||
|
||||
@Field(() => ID, { nullable: true })
|
||||
person?: string;
|
||||
|
||||
}
|
||||
|
||||
@InputType()
|
||||
export class UpdateBuildAttributeInput {
|
||||
|
||||
@Field(() => ID, { nullable: true })
|
||||
site?: string;
|
||||
|
||||
@Field(() => ID, { nullable: true })
|
||||
address?: string;
|
||||
|
||||
@Field(() => [ID], { nullable: true })
|
||||
areas?: string[];
|
||||
|
||||
@Field(() => [ID], { nullable: true })
|
||||
ibans?: string[];
|
||||
|
||||
@Field(() => [UpdateResponsibleInput], { nullable: true })
|
||||
responsibles?: UpdateResponsibleInput[];
|
||||
|
||||
}
|
||||
|
||||
@InputType()
|
||||
export class UpdateBuildResponsibleInput {
|
||||
|
||||
@Field(() => ID, { nullable: true })
|
||||
company?: string;
|
||||
|
||||
@Field(() => ID, { nullable: true })
|
||||
person?: string;
|
||||
|
||||
}
|
||||
62
backend/src/builds/example.graphql
Normal file
62
backend/src/builds/example.graphql
Normal file
@@ -0,0 +1,62 @@
|
||||
mutation CreateBuild($input: CreateBuildInput!) {
|
||||
createBuild(input: $input) {
|
||||
_id
|
||||
uuid
|
||||
createdAt
|
||||
expiryStarts
|
||||
expiryEnds
|
||||
buildType
|
||||
collectionToken
|
||||
ibans
|
||||
responsibles {
|
||||
company
|
||||
person
|
||||
}
|
||||
areas
|
||||
info {
|
||||
govAddressCode
|
||||
buildName
|
||||
buildNo
|
||||
maxFloor
|
||||
undergroundFloor
|
||||
buildDate
|
||||
decisionPeriodDate
|
||||
taxNo
|
||||
liftCount
|
||||
heatingSystem
|
||||
coolingSystem
|
||||
hotWaterSystem
|
||||
blockServiceManCount
|
||||
securityServiceManCount
|
||||
garageCount
|
||||
managementRoomId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
"input": {
|
||||
"expiryStarts": "2025-01-10T08:00:00.000Z",
|
||||
"expiryEnds": "2099-12-31T00:00:00.000Z",
|
||||
"buildType": "675abc12ef90123456789aaa",
|
||||
"collectionToken": "COLL-TEST-2025-XYZ",
|
||||
"info": {
|
||||
"govAddressCode": "TR-34-12345",
|
||||
"buildName": "Aether Residence",
|
||||
"buildNo": "B-12",
|
||||
"maxFloor": 12,
|
||||
"undergroundFloor": 2,
|
||||
"buildDate": "2020-06-15T00:00:00.000Z",
|
||||
"decisionPeriodDate": "2020-05-01T00:00:00.000Z",
|
||||
"taxNo": "12345678901",
|
||||
"liftCount": 3,
|
||||
"heatingSystem": true,
|
||||
"coolingSystem": true,
|
||||
"hotWaterSystem": true,
|
||||
"blockServiceManCount": 2,
|
||||
"securityServiceManCount": 1,
|
||||
"garageCount": 30,
|
||||
"managementRoomId": 101
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,75 +1,75 @@
|
||||
import { Prop } from '@nestjs/mongoose';
|
||||
import { randomUUID } from 'crypto';
|
||||
import { ObjectType, InputType, Field, ID } from '@nestjs/graphql';
|
||||
import { ObjectType, InputType, Field } from '@nestjs/graphql';
|
||||
|
||||
@ObjectType({ isAbstract: true })
|
||||
export class Base {
|
||||
|
||||
@Field()
|
||||
@Prop({ default: randomUUID, unique: true })
|
||||
@Field({ nullable: true })
|
||||
@Prop({ default: () => randomUUID(), unique: true })
|
||||
uuid: string;
|
||||
|
||||
@Field()
|
||||
@Field({ nullable: true })
|
||||
@Prop({ default: () => new Date(Date.now()) })
|
||||
createdAt: Date;
|
||||
|
||||
@Field()
|
||||
@Field({ nullable: true })
|
||||
@Prop({ default: () => new Date(Date.now()) })
|
||||
updatedAt: Date;
|
||||
|
||||
@Field()
|
||||
@Field({ nullable: true })
|
||||
@Prop({ default: false, required: false })
|
||||
isConfirmed?: boolean;
|
||||
|
||||
@Field()
|
||||
@Field({ nullable: true })
|
||||
@Prop({ default: false, required: false })
|
||||
deleted?: boolean;
|
||||
|
||||
@Field()
|
||||
@Field({ nullable: true })
|
||||
@Prop({ default: true, required: false })
|
||||
active?: boolean;
|
||||
|
||||
@Field()
|
||||
@Field({ nullable: true })
|
||||
@Prop({ default: randomUUID })
|
||||
crypUuId: string;
|
||||
|
||||
@Field()
|
||||
@Field({ nullable: true })
|
||||
@Prop({ default: randomUUID })
|
||||
createdCredentialsToken: string;
|
||||
|
||||
@Field()
|
||||
@Field({ nullable: true })
|
||||
@Prop({ default: randomUUID })
|
||||
updatedCredentialsToken: string;
|
||||
|
||||
@Field()
|
||||
@Field({ nullable: true })
|
||||
@Prop({ default: randomUUID })
|
||||
confirmedCredentialsToken: string;
|
||||
|
||||
@Field()
|
||||
@Field({ nullable: true })
|
||||
@Prop({ default: false, required: false })
|
||||
isNotificationSend?: boolean;
|
||||
|
||||
@Field()
|
||||
@Field({ nullable: true })
|
||||
@Prop({ default: false, required: false })
|
||||
isEmailSend?: boolean;
|
||||
|
||||
@Field()
|
||||
@Field({ nullable: true })
|
||||
@Prop({ default: 0 })
|
||||
refInt: number;
|
||||
|
||||
@Field()
|
||||
@Field({ nullable: true })
|
||||
@Prop({ default: randomUUID })
|
||||
refId: string;
|
||||
|
||||
@Field()
|
||||
@Field({ nullable: true })
|
||||
@Prop({ default: 0 })
|
||||
replicationId: number;
|
||||
|
||||
@Field()
|
||||
@Field({ nullable: true })
|
||||
@Prop({ default: () => new Date(Date.now()), required: false })
|
||||
expiryStarts?: Date;
|
||||
|
||||
@Field()
|
||||
@Field({ nullable: true })
|
||||
@Prop({ default: () => new Date('2099-12-31'), required: false })
|
||||
expiryEnds?: Date;
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
||||
import { Document, Types } from 'mongoose';
|
||||
import { ObjectType, Field, ID, Int } from '@nestjs/graphql';
|
||||
import { Base, ChangableBase } from '@/models/base.model';
|
||||
import { Base } from '@/models/base.model';
|
||||
import { Person } from '@/models/person.model';
|
||||
import { Company } from '@/models/company.model';
|
||||
|
||||
@ObjectType()
|
||||
@Schema({ timestamps: true })
|
||||
export class BuildIban extends ChangableBase {
|
||||
export class BuildIban extends Base {
|
||||
|
||||
@Field(() => ID)
|
||||
readonly _id: string;
|
||||
@@ -37,13 +37,13 @@ export class BuildIban extends ChangableBase {
|
||||
@ObjectType()
|
||||
export class BuildResponsible {
|
||||
|
||||
@Field(() => ID)
|
||||
@Prop({ type: Types.ObjectId, ref: Company.name, required: true })
|
||||
company: Types.ObjectId;
|
||||
@Field(() => [String], { nullable: true, defaultValue: [] })
|
||||
@Prop({ type: [String], default: [] })
|
||||
company?: string[];
|
||||
|
||||
@Field(() => ID)
|
||||
@Prop({ type: Types.ObjectId, ref: Person.name, required: true })
|
||||
person: Types.ObjectId;
|
||||
@Field(() => [String], { nullable: true, defaultValue: [] })
|
||||
@Prop({ type: [String], default: [] })
|
||||
person?: string[];
|
||||
|
||||
}
|
||||
|
||||
@@ -118,38 +118,45 @@ export class BuildInfo {
|
||||
|
||||
@ObjectType()
|
||||
@Schema({ timestamps: true })
|
||||
export class Build extends Base {
|
||||
|
||||
@Field(() => ID)
|
||||
@Prop({ type: Types.ObjectId, ref: 'BuildType', required: true })
|
||||
buildType: Types.ObjectId;
|
||||
export class Build {
|
||||
|
||||
@Field()
|
||||
@Prop({ required: true, unique: true })
|
||||
readonly _id: string;
|
||||
|
||||
// @Field(() => ID)
|
||||
// @Prop({ type: Types.ObjectId, ref: 'BuildType', required: true })
|
||||
// buildType: Types.ObjectId;
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
@Prop({ required: true })
|
||||
buildType: string;
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
@Prop({ required: true })
|
||||
collectionToken: string;
|
||||
|
||||
@Field(() => BuildInfo)
|
||||
@Field(() => BuildInfo, { nullable: true })
|
||||
@Prop({ type: BuildInfo, required: true })
|
||||
info: BuildInfo;
|
||||
|
||||
@Field(() => ID, { nullable: true })
|
||||
@Prop({ type: Types.ObjectId, ref: 'BuildSites' })
|
||||
site?: Types.ObjectId;
|
||||
@Field(() => String, { nullable: true })
|
||||
@Prop({ type: String })
|
||||
site?: string;
|
||||
|
||||
@Field(() => ID, { nullable: true })
|
||||
@Prop({ type: Types.ObjectId, ref: 'BuildAddress' })
|
||||
address?: Types.ObjectId;
|
||||
@Field(() => String, { nullable: true })
|
||||
@Prop({ type: String })
|
||||
address?: string;
|
||||
|
||||
@Field(() => [ID], { nullable: true })
|
||||
@Prop({ type: [{ type: Types.ObjectId, ref: 'BuildArea' }] })
|
||||
areas?: Types.ObjectId[];
|
||||
@Field(() => [String], { nullable: true, defaultValue: [] })
|
||||
@Prop({ type: [String], default: [] })
|
||||
areas?: string[];
|
||||
|
||||
@Field(() => [BuildIban], { nullable: true })
|
||||
@Prop({ type: [BuildIban] })
|
||||
ibans?: BuildIban[];
|
||||
@Field(() => [String], { nullable: true, defaultValue: [] })
|
||||
@Prop({ type: [String], default: [] })
|
||||
ibans?: string[];
|
||||
|
||||
@Field(() => [BuildResponsible], { nullable: true })
|
||||
@Prop({ type: [BuildResponsible] })
|
||||
@Field(() => [BuildResponsible], { nullable: true, defaultValue: [] })
|
||||
@Prop({ type: [BuildResponsible], default: [] })
|
||||
responsibles?: BuildResponsible[];
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user