Skip to content

Commit

Permalink
Poke: fix search by user email
Browse files Browse the repository at this point in the history
  • Loading branch information
PopDaph committed Feb 20, 2024
1 parent a2e57c0 commit 1121ed0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
4 changes: 0 additions & 4 deletions front/lib/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import type {
ForeignKey,
InferAttributes,
InferCreationAttributes,
NonAttribute,
} from "sequelize";
import { DataTypes, Model } from "sequelize";

import { front_sequelize } from "@app/lib/databases";
import type { Membership } from "@app/lib/models";

export class User extends Model<
InferAttributes<User>,
Expand All @@ -27,8 +25,6 @@ export class User extends Model<
declare imageUrl: string | null;

declare isDustSuperUser: CreationOptional<boolean>;

declare memberships: NonAttribute<Membership[]>;
}
User.init(
{
Expand Down
24 changes: 13 additions & 11 deletions front/pages/api/poke/workspaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,22 @@ async function handler(
where: {
email: search,
},
include: [
{
model: Membership,
attributes: ["workspaceId"],
},
],
});
if (user?.memberships) {
conditions.push({
id: {
[Op.in]: user?.memberships.map((m) => m.workspaceId),
if (user) {
const memberships = await Membership.findAll({
where: {
userId: user.id,
},
attributes: ["workspaceId"],
});
isSearchByEmail = true;
if (memberships.length) {
conditions.push({
id: {
[Op.in]: memberships.map((m) => m.workspaceId),
},
});
isSearchByEmail = true;
}
}
}

Expand Down

0 comments on commit 1121ed0

Please sign in to comment.