Skip to content

Commit

Permalink
feat(populate): fixed query populate bug
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiin committed Apr 30, 2022
1 parent fdb72a9 commit 0480bac
Show file tree
Hide file tree
Showing 12 changed files with 403 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ultimate-nest-template",
"version": "1.4.5",
"version": "1.5.0",
"description": "NestJS + MikroORM realworld API example",
"license": "MIT",
"repository": "https://github.com/rubiin/ultimate-nest",
Expand Down
4 changes: 2 additions & 2 deletions src/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class User extends BaseEntity {
this.password = await HelperService.hashString(this.password);
}

@OneToMany(() => Post, post => post.author, { hidden: true })
@OneToMany(() => Post, post => post.author)
posts = new Collection<Post>(this);

@ManyToMany({ hidden: true })
Expand All @@ -70,7 +70,7 @@ export class User extends BaseEntity {
})
followers = new Collection<User>(this);

@ManyToMany(() => User, u => u.followers, { hidden: true })
@ManyToMany(() => User, u => u.followers)
followed = new Collection<User>(this);

toJSON() {
Expand Down
7 changes: 0 additions & 7 deletions src/modules/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,4 @@ export class AuthController {
? this.authService.logoutFromAll(user)
: this.authService.logout(user, refreshToken.refreshToken);
}

@ApiOperation({ summary: "User profile" })
@Auth()
@Get("profile")
profile(@LoggedInUser() user: UserEntity) {
return user;
}
}
22 changes: 13 additions & 9 deletions src/modules/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,20 @@ export class UserService {

await em.persistAndFlush(user);

await this.amqpConnection.publish("nestify", "send-mail", {
template: EmailTemplateEnum.WELCOME_TEMPLATE,
replacements: {
firstName: capitalize(user.firstName),
link: "example.com",
await this.amqpConnection.publish(
this.configService.get<string>("rabbit.exchange"),
"send-mail",
{
template: EmailTemplateEnum.WELCOME_TEMPLATE,
replacements: {
firstName: capitalize(user.firstName),
link: "example.com",
},
to: user.email,
subject: "Welcome onboard",
from: this.configService.get("mail.senderEmail"),
},
to: user.email,
subject: "Welcome onboard",
from: this.configService.get("mail.senderEmail"),
});
);
});

return user;
Expand Down
43 changes: 43 additions & 0 deletions temp/ActivityLog.js.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"data": {
"propertyOrder": {},
"properties": {
"activityType": { "name": "activityType", "reference": "scalar", "length": 50, "getter": false, "setter": false, "type": "string", "nullable": true },
"loginType": { "name": "loginType", "reference": "scalar", "length": 50, "getter": false, "setter": false, "type": "string", "nullable": true },
"ipAddress": { "name": "ipAddress", "reference": "scalar", "length": 50, "getter": false, "setter": false, "type": "string", "nullable": true },
"deviceId": { "name": "deviceId", "reference": "scalar", "length": 50, "getter": false, "setter": false, "type": "string", "nullable": true },
"status": { "name": "status", "reference": "scalar", "getter": false, "setter": false, "type": "boolean" },
"loginStatus": { "name": "loginStatus", "reference": "scalar", "getter": false, "setter": false, "type": "boolean" },
"user": { "name": "user", "reference": "m:1", "cascade": ["persist"], "type": "User", "nullable": false }
},
"props": [
{ "name": "activityType", "reference": "scalar", "length": 50, "getter": false, "setter": false, "type": "string", "nullable": true },
{ "name": "loginType", "reference": "scalar", "length": 50, "getter": false, "setter": false, "type": "string", "nullable": true },
{ "name": "ipAddress", "reference": "scalar", "length": 50, "getter": false, "setter": false, "type": "string", "nullable": true },
{ "name": "deviceId", "reference": "scalar", "length": 50, "getter": false, "setter": false, "type": "string", "nullable": true },
{ "name": "status", "reference": "scalar", "getter": false, "setter": false, "type": "boolean" },
{ "name": "loginStatus", "reference": "scalar", "getter": false, "setter": false, "type": "boolean" },
{ "name": "user", "reference": "m:1", "cascade": ["persist"], "type": "User", "nullable": false }
],
"primaryKeys": [],
"filters": {},
"hooks": {},
"indexes": [],
"uniques": [],
"checks": [],
"concurrencyCheckKeys": {},
"className": "ActivityLog",
"path": "./dist/entities/activity-log.entity.js",
"name": "ActivityLog",
"abstract": false,
"constructorParams": [],
"toJsonParams": [],
"extends": "BaseEntity",
"useCache": true,
"relations": [{ "name": "user", "reference": "m:1", "cascade": ["persist"], "type": "User", "nullable": false }],
"collection": "activity_log"
},
"origin": "./dist/entities/activity-log.entity.js",
"hash": "119c1e9dca7e0d9cc073c77349e93a66",
"version": "5.1.3"
}
41 changes: 41 additions & 0 deletions temp/BaseEntity.js.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"data": {
"propertyOrder": {},
"properties": {
"id": { "name": "id", "reference": "scalar", "primary": true, "hidden": true, "type": "number" },
"idx": { "name": "idx", "reference": "scalar", "getter": false, "setter": false, "type": "string" },
"isActive": { "name": "isActive", "reference": "scalar", "getter": false, "setter": false, "type": "boolean" },
"isObsolete": { "name": "isObsolete", "reference": "scalar", "hidden": true, "getter": false, "setter": false, "type": "boolean" },
"deletedAt": { "name": "deletedAt", "reference": "scalar", "getter": false, "setter": false, "type": "Date", "nullable": true },
"createdAt": { "name": "createdAt", "reference": "scalar", "getter": false, "setter": false, "type": "Date" },
"updatedAt": { "name": "updatedAt", "reference": "scalar", "hidden": true, "getter": false, "setter": false, "type": "Date", "nullable": true }
},
"props": [
{ "name": "id", "reference": "scalar", "primary": true, "hidden": true, "type": "number" },
{ "name": "idx", "reference": "scalar", "getter": false, "setter": false, "type": "string" },
{ "name": "isActive", "reference": "scalar", "getter": false, "setter": false, "type": "boolean" },
{ "name": "isObsolete", "reference": "scalar", "hidden": true, "getter": false, "setter": false, "type": "boolean" },
{ "name": "deletedAt", "reference": "scalar", "getter": false, "setter": false, "type": "Date", "nullable": true },
{ "name": "createdAt", "reference": "scalar", "getter": false, "setter": false, "type": "Date" },
{ "name": "updatedAt", "reference": "scalar", "hidden": true, "getter": false, "setter": false, "type": "Date", "nullable": true }
],
"primaryKeys": ["id"],
"filters": {},
"hooks": {},
"indexes": [],
"uniques": [],
"checks": [],
"concurrencyCheckKeys": {},
"className": "BaseEntity",
"path": "./dist/common/database/base-entity.entity.js",
"abstract": true,
"constructorParams": [],
"toJsonParams": [],
"useCache": true,
"compositePK": false,
"relations": []
},
"origin": "./dist/common/database/base-entity.entity.js",
"hash": "99e78948829038cbac77d4fb363a4c51",
"version": "5.1.3"
}
38 changes: 38 additions & 0 deletions temp/Comment.js.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"data": {
"propertyOrder": {},
"properties": {
"body": { "name": "body", "reference": "scalar", "getter": false, "setter": false, "type": "string" },
"post": { "name": "post", "reference": "m:1", "cascade": ["persist"], "type": "Post", "nullable": false },
"author": { "name": "author", "reference": "m:1", "cascade": ["persist"], "type": "User", "nullable": false }
},
"props": [
{ "name": "body", "reference": "scalar", "getter": false, "setter": false, "type": "string" },
{ "name": "post", "reference": "m:1", "cascade": ["persist"], "type": "Post", "nullable": false },
{ "name": "author", "reference": "m:1", "cascade": ["persist"], "type": "User", "nullable": false }
],
"primaryKeys": [],
"filters": {},
"hooks": {},
"indexes": [],
"uniques": [],
"checks": [],
"concurrencyCheckKeys": {},
"className": "Comment",
"path": "./dist/entities/comment.entity.js",
"name": "Comment",
"abstract": false,
"constructorParams": ["author", "post", "body"],
"toJsonParams": [],
"extends": "BaseEntity",
"useCache": true,
"relations": [
{ "name": "post", "reference": "m:1", "cascade": ["persist"], "type": "Post", "nullable": false },
{ "name": "author", "reference": "m:1", "cascade": ["persist"], "type": "User", "nullable": false }
],
"collection": "comment"
},
"origin": "./dist/entities/comment.entity.js",
"hash": "45a0c9cab4433cf9bb3ec3b4ddd16ea8",
"version": "5.1.3"
}
37 changes: 37 additions & 0 deletions temp/OtpLog.js.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"data": {
"propertyOrder": {},
"properties": {
"expiresIn": { "name": "expiresIn", "reference": "scalar", "getter": false, "setter": false, "type": "Date" },
"otpCode": { "name": "otpCode", "reference": "scalar", "length": 20, "getter": false, "setter": false, "type": "string", "nullable": true },
"user": { "name": "user", "reference": "m:1", "cascade": ["persist"], "type": "User", "nullable": false },
"isUsed": { "name": "isUsed", "reference": "scalar", "getter": false, "setter": false, "type": "boolean" }
},
"props": [
{ "name": "expiresIn", "reference": "scalar", "getter": false, "setter": false, "type": "Date" },
{ "name": "otpCode", "reference": "scalar", "length": 20, "getter": false, "setter": false, "type": "string", "nullable": true },
{ "name": "user", "reference": "m:1", "cascade": ["persist"], "type": "User", "nullable": false },
{ "name": "isUsed", "reference": "scalar", "getter": false, "setter": false, "type": "boolean" }
],
"primaryKeys": [],
"filters": {},
"hooks": {},
"indexes": [],
"uniques": [],
"checks": [],
"concurrencyCheckKeys": {},
"className": "OtpLog",
"path": "./dist/entities/otp-log.entity.js",
"name": "OtpLog",
"abstract": false,
"constructorParams": [],
"toJsonParams": [],
"extends": "BaseEntity",
"useCache": true,
"relations": [{ "name": "user", "reference": "m:1", "cascade": ["persist"], "type": "User", "nullable": false }],
"collection": "otp_log"
},
"origin": "./dist/entities/otp-log.entity.js",
"hash": "654243168518b0d960b84dfc4e887bdf",
"version": "5.1.3"
}
48 changes: 48 additions & 0 deletions temp/Post.js.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"data": {
"propertyOrder": {},
"properties": {
"slug": { "name": "slug", "reference": "scalar", "getter": false, "setter": false, "type": "string" },
"title": { "name": "title", "reference": "scalar", "getter": false, "setter": false, "type": "string" },
"description": { "name": "description", "reference": "scalar", "getter": false, "setter": false, "type": "string" },
"content": { "name": "content", "reference": "scalar", "type": "text", "getter": false, "setter": false },
"tags": { "name": "tags", "reference": "scalar", "getter": false, "setter": false, "array": true },
"author": { "name": "author", "reference": "m:1", "cascade": ["persist"], "eager": false, "type": "User", "nullable": false },
"comments": { "name": "comments", "reference": "1:m", "cascade": ["persist"], "eager": false, "orphanRemoval": true, "type": "Comment" },
"favoritesCount": { "name": "favoritesCount", "reference": "scalar", "getter": false, "setter": false, "type": "number" }
},
"props": [
{ "name": "slug", "reference": "scalar", "getter": false, "setter": false, "type": "string" },
{ "name": "title", "reference": "scalar", "getter": false, "setter": false, "type": "string" },
{ "name": "description", "reference": "scalar", "getter": false, "setter": false, "type": "string" },
{ "name": "content", "reference": "scalar", "type": "text", "getter": false, "setter": false },
{ "name": "tags", "reference": "scalar", "getter": false, "setter": false, "array": true },
{ "name": "author", "reference": "m:1", "cascade": ["persist"], "eager": false, "type": "User", "nullable": false },
{ "name": "comments", "reference": "1:m", "cascade": ["persist"], "eager": false, "orphanRemoval": true, "type": "Comment" },
{ "name": "favoritesCount", "reference": "scalar", "getter": false, "setter": false, "type": "number" }
],
"primaryKeys": [],
"filters": {},
"hooks": {},
"indexes": [],
"uniques": [],
"checks": [],
"concurrencyCheckKeys": {},
"className": "Post",
"path": "./dist/entities/post.entity.js",
"name": "Post",
"abstract": false,
"constructorParams": ["author", "title", "description", "body"],
"toJsonParams": [],
"extends": "BaseEntity",
"useCache": true,
"relations": [
{ "name": "author", "reference": "m:1", "cascade": ["persist"], "eager": false, "type": "User", "nullable": false },
{ "name": "comments", "reference": "1:m", "cascade": ["persist"], "eager": false, "orphanRemoval": true, "type": "Comment" }
],
"collection": "post"
},
"origin": "./dist/entities/post.entity.js",
"hash": "7ee92987abab980f7abddc5cc9c54ae2",
"version": "5.1.3"
}
43 changes: 43 additions & 0 deletions temp/Protocol.js.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"data": {
"propertyOrder": {},
"properties": {
"loginAttemptnumbererval": { "name": "loginAttemptnumbererval", "reference": "scalar", "getter": false, "setter": false, "type": "number" },
"loginnumberervalUnit": { "name": "loginnumberervalUnit", "reference": "scalar", "getter": false, "setter": false, "type": "string" },
"loginMaxRetry": { "name": "loginMaxRetry", "reference": "scalar", "getter": false, "setter": false, "type": "number" },
"otpExpiryInMinutes": { "name": "otpExpiryInMinutes", "reference": "scalar", "getter": false, "setter": false, "type": "number" },
"mpinAttemptInterval": { "name": "mpinAttemptInterval", "reference": "scalar", "getter": false, "setter": false, "type": "number" },
"mpinIntervalUnit": { "name": "mpinIntervalUnit", "reference": "scalar", "getter": false, "setter": false, "type": "string" },
"mpinMaxRetry": { "name": "mpinMaxRetry", "reference": "scalar", "getter": false, "setter": false, "type": "number" }
},
"props": [
{ "name": "loginAttemptnumbererval", "reference": "scalar", "getter": false, "setter": false, "type": "number" },
{ "name": "loginnumberervalUnit", "reference": "scalar", "getter": false, "setter": false, "type": "string" },
{ "name": "loginMaxRetry", "reference": "scalar", "getter": false, "setter": false, "type": "number" },
{ "name": "otpExpiryInMinutes", "reference": "scalar", "getter": false, "setter": false, "type": "number" },
{ "name": "mpinAttemptInterval", "reference": "scalar", "getter": false, "setter": false, "type": "number" },
{ "name": "mpinIntervalUnit", "reference": "scalar", "getter": false, "setter": false, "type": "string" },
{ "name": "mpinMaxRetry", "reference": "scalar", "getter": false, "setter": false, "type": "number" }
],
"primaryKeys": [],
"filters": {},
"hooks": {},
"indexes": [],
"uniques": [],
"checks": [],
"concurrencyCheckKeys": {},
"className": "Protocol",
"path": "./dist/entities/protocol.entity.js",
"name": "Protocol",
"abstract": false,
"constructorParams": [],
"toJsonParams": [],
"extends": "BaseEntity",
"useCache": true,
"relations": [],
"collection": "protocol"
},
"origin": "./dist/entities/protocol.entity.js",
"hash": "a65f8797a631a4085829a9788a9c429b",
"version": "5.1.3"
}
35 changes: 35 additions & 0 deletions temp/RefreshToken.js.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"data": {
"propertyOrder": {},
"properties": {
"expiresIn": { "name": "expiresIn", "reference": "scalar", "getter": false, "setter": false, "type": "Date" },
"user": { "name": "user", "reference": "m:1", "cascade": ["persist"], "type": "User", "nullable": false },
"isRevoked": { "name": "isRevoked", "reference": "scalar", "getter": false, "setter": false, "type": "boolean" }
},
"props": [
{ "name": "expiresIn", "reference": "scalar", "getter": false, "setter": false, "type": "Date" },
{ "name": "user", "reference": "m:1", "cascade": ["persist"], "type": "User", "nullable": false },
{ "name": "isRevoked", "reference": "scalar", "getter": false, "setter": false, "type": "boolean" }
],
"primaryKeys": [],
"filters": {},
"hooks": {},
"indexes": [],
"uniques": [],
"checks": [],
"concurrencyCheckKeys": {},
"className": "RefreshToken",
"path": "./dist/entities/refresh-token.entity.js",
"name": "RefreshToken",
"abstract": false,
"constructorParams": [],
"toJsonParams": [],
"extends": "BaseEntity",
"useCache": true,
"relations": [{ "name": "user", "reference": "m:1", "cascade": ["persist"], "type": "User", "nullable": false }],
"collection": "refresh_token"
},
"origin": "./dist/entities/refresh-token.entity.js",
"hash": "e7be13281e33735088740e789e602817",
"version": "5.1.3"
}
Loading

0 comments on commit 0480bac

Please sign in to comment.