fix: db error on token auth and permission issue

This commit is contained in:
=
2024-11-22 22:41:53 +05:30
parent 1a084d8fcf
commit 93208afb36
2 changed files with 7 additions and 6 deletions
@@ -127,14 +127,15 @@ export const permissionDALFactory = (db: TDbClient) => {
const getProjectPermission = async (userId: string, projectId: string) => { const getProjectPermission = async (userId: string, projectId: string) => {
try { try {
const subQueryUserGroups = db(TableName.UserGroupMembership).where("userId", userId).select("groupId");
const docs = await db const docs = await db
.replicaNode()(TableName.Users) .replicaNode()(TableName.Users)
.where(`${TableName.Users}.id`, userId) .where(`${TableName.Users}.id`, userId)
.leftJoin(TableName.UserGroupMembership, `${TableName.UserGroupMembership}.userId`, `${TableName.Users}.id`)
.leftJoin(TableName.GroupProjectMembership, (queryBuilder) => { .leftJoin(TableName.GroupProjectMembership, (queryBuilder) => {
void queryBuilder void queryBuilder
.on(`${TableName.GroupProjectMembership}.projectId`, db.raw("?", [projectId])) .on(`${TableName.GroupProjectMembership}.projectId`, db.raw("?", [projectId]))
.andOn(`${TableName.GroupProjectMembership}.groupId`, `${TableName.UserGroupMembership}.groupId`); // @ts-expect-error akhilmhdh: this is valid knexjs query. Its just ts type argument is missing it
.andOnIn(`${TableName.GroupProjectMembership}.groupId`, subQueryUserGroups);
}) })
.leftJoin( .leftJoin(
TableName.GroupProjectMembershipRole, TableName.GroupProjectMembershipRole,
@@ -385,8 +385,8 @@ export const identityTokenAuthServiceFactory = ({
actorOrgId actorOrgId
}: TUpdateTokenAuthTokenDTO) => { }: TUpdateTokenAuthTokenDTO) => {
const foundToken = await identityAccessTokenDAL.findOne({ const foundToken = await identityAccessTokenDAL.findOne({
id: tokenId, [`${TableName.IdentityAccessToken}.id` as "id"]: tokenId,
authMethod: IdentityAuthMethod.TOKEN_AUTH [`${TableName.IdentityAccessToken}.authMethod` as "authMethod"]: IdentityAuthMethod.TOKEN_AUTH
}); });
if (!foundToken) throw new NotFoundError({ message: `Token with ID ${tokenId} not found` }); if (!foundToken) throw new NotFoundError({ message: `Token with ID ${tokenId} not found` });
@@ -444,8 +444,8 @@ export const identityTokenAuthServiceFactory = ({
}: TRevokeTokenAuthTokenDTO) => { }: TRevokeTokenAuthTokenDTO) => {
const identityAccessToken = await identityAccessTokenDAL.findOne({ const identityAccessToken = await identityAccessTokenDAL.findOne({
[`${TableName.IdentityAccessToken}.id` as "id"]: tokenId, [`${TableName.IdentityAccessToken}.id` as "id"]: tokenId,
isAccessTokenRevoked: false, [`${TableName.IdentityAccessToken}.isAccessTokenRevoked` as "isAccessTokenRevoked"]: false,
authMethod: IdentityAuthMethod.TOKEN_AUTH [`${TableName.IdentityAccessToken}.authMethod` as "authMethod"]: IdentityAuthMethod.TOKEN_AUTH
}); });
if (!identityAccessToken) if (!identityAccessToken)
throw new NotFoundError({ throw new NotFoundError({