我正在使用entitymanager.findOne方法获取对象 ChatRoomEntity 。ChatRoomEntity 有一个变量messages,它是一个 OneToMany - ManyToOne Relation。我没有问题可以选择它,但是如何获取发送消息的用户。它是 MessageEntity 上的一个变量,具有 OneToMany 关系。
所以基本上我想选择一个房间和它的所有消息。但是所有消息也应该有它们的值fromUser。我选择这样的房间:
this.entityManager.findOne(ChatRoomEntity, {where: {id: roomToJoin.id}, relations: ['activeUsers', 'messages']}).then(roomEntity => {
// some code
}
Run Code Online (Sandbox Code Playgroud)
这是我的实体:
用户实体
@Entity()
export class UserEntity {
@PrimaryGeneratedColumn()
id: number;
@CreateDateColumn()
registrationDate: Date;
@ManyToMany(type => ChatRoomEntity, room => room.activeUsers, {cascade: true})
@JoinTable()
activeChatRooms: ChatRoomEntity[];
@OneToMany(type => ChatRoomMessageEntity, msg => msg.fromUser)
chatRoomMessages: ChatRoomMessageEntity[];
}
Run Code Online (Sandbox Code Playgroud)
聊天室实体
@Entity()
export class ChatRoomEntity {
@PrimaryGeneratedColumn()
id: number;
@Column('varchar', {nullable: true})
title: string;
@OneToMany(type …Run Code Online (Sandbox Code Playgroud) 我正在为我的项目使用默认的护照 jwt AuthGuard。这适用于我的帖子,并在设置身份验证标头时很好地获取路由。
现在我想在客户端将 Nestjs 网关与 socket.io 一起使用,但我不知道如何将 access_token 发送到网关?
这基本上是我的网关:
@WebSocketGateway()
export class UserGateway {
entityManager = getManager();
@UseGuards(AuthGuard('jwt'))
@SubscribeMessage('getUserList')
async handleMessage(client: any, payload: any) {
const results = await this.entityManager.find(UserEntity);
console.log(results);
return this.entityToClientUser(results);
}
Run Code Online (Sandbox Code Playgroud)
在客户端我发送这样的:
this.socket.emit('getUserList', users => {
console.log(users);
this.userListSub.next(users);
});
Run Code Online (Sandbox Code Playgroud)
如何以及在哪里添加 jwt access_token?nestjs 的文档完全忽略了 Websockets 的这一点。他们说的是,Guards 对 websockets 的工作方式与他们对 post/get 等的工作方式完全相同。见这里
我按照基本步骤来设置 ngx-quill。经过一些研究,我还安装了 ngx-quill 和 quill。但我仍然得到同样的错误。
ERROR in Directive QuillEditorBase in .../node_modules/ngx-quill/ngx-quill.d.ts has no selector, please add it!
Cannot determine the module for class QuillEditorBase .../node_modules/ngx-quill/ngx-quill.d.ts! Add QuillEditorBase to the NgModule to fix it.
Run Code Online (Sandbox Code Playgroud)
我简单地使用 eidtor <quill-editor></quill-editor>
我使用它的组件是延迟加载的。我添加QuillModule.forRoot()到我的主模块的导入中,并尝试将其添加到我的延迟加载模块中。然后我尝试将它添加到两者中,我也尝试将它添加到没有forRoot(). 错误保持不变。我不知道应该在哪里将 QuillEditorBase 添加到 ngmodule 中。
我究竟做错了什么?我没有自定义配置。我刚刚安装了它并想尝试让它工作..
我按照本教程添加了路线过渡动画,它似乎有效,但我的应用程序中有超过 3 条路线。现在,当我转到animation: 'isRight'当前所在的页面时,isLeft它按预期工作,但是当我已经在isRight并想转到当前页面右侧的另一个页面时,它根本不显示任何过渡。
我如何根据我目前的位置进行过渡?我怎么知道我是否必须向左或向右过渡?
这是我的路线的一个例子:
const routes: Routes = [
{ path: 'page1', component: Page1Component, data: {animation: isLeft} },
{ path: 'page2', component: Page2Component, data: { animation: 'isRight' } },
{ path: 'page3', component: Page3Component, data: { animation: 'isRight' } },
{ path: 'page4', component: Page4Component, data: { animation: 'isRight' } },
{ path: 'page5', component: Page5Component, data: { animation: 'isRight' } },
{ path: 'page6', component: Page6Component, data: { animation: …Run Code Online (Sandbox Code Playgroud) 试图使元素可排序,但它不适用于多个容器。在 jsFiddle 中,您会看到第一个 Container 有效,但第二个无效?
$("#sortable").sortable({
cancel: ".fixed"
});
$("#sortable").disableSelection();
Run Code Online (Sandbox Code Playgroud)
HTML:
<div class="demo">
<ul id="sortable">
<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 1</li>
<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 2</li>
<li class="ui-state-default fixed"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 3</li>
<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 4</li>
<li class="ui-state-default fixed"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 5</li>
<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 6</li>
<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 7</li>
</ul>
<hr/>
<ul id="sortable">
<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 1</li>
<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 2</li>
<li class="ui-state-default fixed"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 3</li>
<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 4</li>
<li class="ui-state-default fixed"><span …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 jwt-passport 和 nestjs 来设置一个非常简单的登录系统。我遵循了本教程:https : //docs.nestjs.com/techniques/authentication但我无法让它工作。我对这些东西真的很陌生,如果有人能给我指路,我将不胜感激。
我将登录名发送到服务器的方式:
this.clientAuthService.login(this.userName, this.password).then(response => {
this.clientAuthService.setToken(response.access_token);
this.router.navigate(['/backend']);
});
Run Code Online (Sandbox Code Playgroud)
我的 ClientAuthService:
export class ClientAuthService {
constructor(private http: HttpClient, @Inject(PLATFORM_ID) private platformId) {
}
getToken(): string {
if (isPlatformBrowser(this.platformId)) {
return localStorage.getItem(TOKEN_NAME);
} else {
return '';
}
}
setToken(token: string): void {
if (isPlatformBrowser(this.platformId)) {
localStorage.setItem(TOKEN_NAME, token);
}
}
removeToken() {
if (isPlatformBrowser(this.platformId)) {
localStorage.removeItem(TOKEN_NAME);
}
}
getTokenExpirationDate(token: string): Date {
const decoded = jwt_decode(token);
if (decoded.exp === undefined) {
return null; …Run Code Online (Sandbox Code Playgroud) 我试图让我的代码工作。现在搜索小时。我发现像类似的问题这一个。但不幸的是,似乎没有人找到解决办法。
在我的自定义插件中,我想将特定项目添加到 WC 购物车并将用户直接重定向到结帐。作为登录用户,它就像一个魅力,但对于客人来说,它在结账时显示一个空白页面(woocommerce_checkout 简码在这种情况下似乎没有返回任何内容)。所以我想出了一个检查,如果购物车是空的。显然是因为“购物车页面”显示“购物车中还没有商品”。
在代码中,我检查购物车是否仍然是空的,但它告诉我不是!
这是我的代码:
if(!$wooID = $wpdb->get_var("SELECT wooID FROM ".$wpdb->prefix."ceb_events WHERE id = $event")) die("ERROR GETTING WOOID");
WC()->cart->empty_cart();
if(!WC()->cart->add_to_cart( $wooID, 1 )) die("CART GOT NOT UPDATED. THERE IS AN ERROR 1.");
if(WC()->cart->get_cart_contents_count() == 0) die("CART GOT NOT UPDATED. THERE IS AN ERROR 2.");
//Here follows the redirect to checkout page
Run Code Online (Sandbox Code Playgroud)
代码运行没有错误。它以登录用户/管理员身份 100% 工作。只是不是作为客人,即使我允许客人在 woocommerce 设置中结帐。