I want to get the prospectousId from Dto, but I am getting the below error:,
tenant.controller.ts
JavaScript
x
9
1
@Post('/promote-prospectus')
2
@HttpCode(HttpStatus.OK)
3
@ApiOperation({ summary: 'Promoting a prospectus to a tenant.' })
4
@ApiResponse({ status: HttpStatus.OK, description: 'successful operation', })
5
async promoteAProspectus(@Res() response: Response, @Body() Dto: promoteProspectousDto) {
6
let result = await this.tenantsService.promoteAProspectus(Dto);
7
return response.status(HttpStatus.CREATED).json({ message: 'Prospectous promoted as a tenant by the system.', data: result });
8
}
9
tenant.service.ts
JavaScript
1
24
24
1
public async promoteAProspectus(Dto: promoteProspectousDto): Promise<Tenants> {
2
/**
3
* Scopes to be implement while promoting a prospectous to a tenant.
4
*
5
* @scope 1 promote the prospectous to a tenant and construct DB.
6
* @scope 2 Configure all default roles for the newly created tenant.
7
* @scope 3 Configure administrator user. & assign the administrator role.
8
*
9
*/
10
11
let prospectus = await this.tenantsRepository.findOne({ Dto.prospectousId });
12
console.log('hyyyyyyyyyyyyyyyyyyyyyyyyyyy', prospectus);
13
if (prospectus) {
14
const { id } = prospectus;
15
// let tenant: Tenants = await this.promoteAsTenant(prospectus);
16
// await this.rolesService.onBoardTenantDefaultRoles(tenant.tenantDb);
17
// let administrator: Users = await this.onBoardAdministratorUser(RequestedBy);
18
// await this.allocateAdministratorRole(administrator, tenant);
19
return tenant;
20
}
21
22
throw new ConflictException(`Unable to promote.`);
23
}
24
tenant.entity.ts
JavaScript
1
43
43
1
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
2
3
export enum ETenantStatus {
4
TRIAL = 'TRIAL',
5
ACTIVE = 'ACTIVE',
6
BLOCKED = 'BLOCKED',
7
ARCHIVED = 'ARCHIVED',
8
}
9
10
@Entity({ name: `${Tenants.name}` })
11
export class Tenants {
12
13
@PrimaryGeneratedColumn('uuid')
14
id: string;
15
16
@Column({ nullable: false })
17
organization: string;
18
19
@Column({ unique: false })
20
db: string;
21
22
@Column({ unique: true })
23
key: string;
24
25
@Column({ unique: true })
26
domain: string;
27
28
@Column({ nullable: false })
29
location: string;
30
31
@Column({ nullable: false })
32
referedBy: string;
33
34
@Column()
35
@CreateDateColumn({ type: 'timestamp without time zone' })
36
public createdAt: Date;
37
38
@Column()
39
@UpdateDateColumn({ type: 'timestamp without time zone' })
40
public updatedAt: Date;
41
}
42
43
dto:
JavaScript
1
47
47
1
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
2
import { IsBoolean, IsNotEmpty } from "class-validator";
3
4
export class tenantsDto {
5
@ApiProperty({ required: true, default: '' })
6
@IsNotEmpty()
7
organization: string;
8
9
@ApiProperty({ required: true, default: '' })
10
@IsNotEmpty()
11
domain: string;
12
13
@ApiPropertyOptional({ default: '' })
14
notes: string;
15
16
@ApiPropertyOptional({ default: '' })
17
db: string;
18
19
@ApiPropertyOptional({ default: '' })
20
@IsNotEmpty()
21
key: string;
22
23
@ApiPropertyOptional({ default: '' })
24
location: string;
25
26
27
@ApiPropertyOptional({ default: '' })
28
referedBy: string;
29
30
@ApiPropertyOptional({ default: false })
31
skipDbMigration: boolean;
32
33
@ApiProperty({ default: true })
34
@IsBoolean()
35
acceptedTermsAndConditions: boolean;
36
}
37
38
export class promoteProspectousDto {
39
@ApiProperty({ required: true, default: '' })
40
@IsNotEmpty()
41
prospectousId: string;
42
43
@ApiProperty({ required: true, default: '' })
44
@IsNotEmpty()
45
key: string;
46
}
47
What to do to achieve this? Thanks in advance!
Advertisement
Answer
Try using the below code. findOne()
is to be replaced by findOneBy()
as they say in their changelog.
JavaScript
1
2
1
let prospectus = await this.tenantsRepository.findOneBy({ id: Dto.prospectousId });
2
See the Changelog of TypeORM for more:
findOne()
signature without parameters was dropped. If you need a single row from the db you can use a following syntax:JavaScript121const [user] = await userRepository.find()
2
findOne(id)
signature was dropped. Use following syntax instead:JavaScript141const user = await userRepository.findOneBy({
2id: id // where id is your column name
3})
4