jwt gen & rename fixes
This commit is contained in:
parent
313785b4ac
commit
a165231c47
13 changed files with 101 additions and 41 deletions
|
@ -33,7 +33,10 @@ export default abstract class MemberCommandHandler {
|
|||
return result.identifiers[0].id;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed creating member", err);
|
||||
throw new InternalException(
|
||||
`Failed creating member${err.code.includes("ER_DUP_ENTRY") ? " due to duplicate entry for column" : ""}`,
|
||||
err
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -58,7 +61,10 @@ export default abstract class MemberCommandHandler {
|
|||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed updating member", err);
|
||||
throw new InternalException(
|
||||
`Failed updating member${err.code.includes("ER_DUP_ENTRY") ? " due to duplicate entry for column" : ""}`,
|
||||
err
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -83,7 +89,7 @@ export default abstract class MemberCommandHandler {
|
|||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed updating member", err);
|
||||
throw new InternalException(`Failed updating member`, err);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,10 @@ export interface UpdateWebapiCommand {
|
|||
expiry?: Date;
|
||||
}
|
||||
|
||||
export interface UpdateLastUsageWebapiCommand {
|
||||
id: number;
|
||||
}
|
||||
|
||||
export interface DeleteWebapiCommand {
|
||||
id: number;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
import { dataSource } from "../../../data-source";
|
||||
import { webapi } from "../../../entity/user/webapi";
|
||||
import InternalException from "../../../exceptions/internalException";
|
||||
import { CreateWebapiCommand, DeleteWebapiCommand, UpdateWebapiCommand } from "./webapiCommand";
|
||||
import {
|
||||
CreateWebapiCommand,
|
||||
DeleteWebapiCommand,
|
||||
UpdateLastUsageWebapiCommand,
|
||||
UpdateWebapiCommand,
|
||||
} from "./webapiCommand";
|
||||
|
||||
export default abstract class WebapiCommandHandler {
|
||||
/**
|
||||
|
@ -24,7 +29,10 @@ export default abstract class WebapiCommandHandler {
|
|||
return result.identifiers[0].token;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed creating api", err);
|
||||
throw new InternalException(
|
||||
`Failed creating api${err.code.includes("ER_DUP_ENTRY") ? " due to duplicate entry for column" : ""}`,
|
||||
err
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -45,7 +53,30 @@ export default abstract class WebapiCommandHandler {
|
|||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed updating api", err);
|
||||
throw new InternalException(
|
||||
`Failed updating api${err.code.includes("ER_DUP_ENTRY") ? " due to duplicate entry for column" : ""}`,
|
||||
err
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description update api usage
|
||||
* @param {UpdateLastUsageWebapiCommand} updateWebapi
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async updateUsage(updateWebapi: UpdateLastUsageWebapiCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.update(webapi)
|
||||
.set({
|
||||
lastUsage: new Date(),
|
||||
})
|
||||
.where("id = :id", { id: updateWebapi.id })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException(`Failed updating api last usage`, err);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -2,15 +2,15 @@ import { PermissionString } from "../../../type/permissionTypes";
|
|||
|
||||
export interface CreateWebapiPermissionCommand {
|
||||
permission: PermissionString;
|
||||
apiId: number;
|
||||
webapiId: number;
|
||||
}
|
||||
|
||||
export interface DeleteWebapiPermissionCommand {
|
||||
permission: PermissionString;
|
||||
apiId: number;
|
||||
webapiId: number;
|
||||
}
|
||||
|
||||
export interface UpdateWebapiPermissionsCommand {
|
||||
apiId: number;
|
||||
webapiId: number;
|
||||
permissions: Array<PermissionString>;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ export default abstract class WebapiPermissionCommandHandler {
|
|||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async updatePermissions(updateWebapiPermissions: UpdateWebapiPermissionsCommand): Promise<void> {
|
||||
let currentPermissions = (await WebapiPermissionService.getByApi(updateWebapiPermissions.apiId)).map(
|
||||
let currentPermissions = (await WebapiPermissionService.getByApi(updateWebapiPermissions.webapiId)).map(
|
||||
(r) => r.permission
|
||||
);
|
||||
return await dataSource.manager
|
||||
|
@ -30,10 +30,10 @@ export default abstract class WebapiPermissionCommandHandler {
|
|||
updateWebapiPermissions.permissions
|
||||
);
|
||||
if (newPermissions.length != 0) {
|
||||
await this.updatePermissionsAdd(manager, updateWebapiPermissions.apiId, newPermissions);
|
||||
await this.updatePermissionsAdd(manager, updateWebapiPermissions.webapiId, newPermissions);
|
||||
}
|
||||
if (removePermissions.length != 0) {
|
||||
await this.updatePermissionsRemove(manager, updateWebapiPermissions.apiId, removePermissions);
|
||||
await this.updatePermissionsRemove(manager, updateWebapiPermissions.webapiId, removePermissions);
|
||||
}
|
||||
})
|
||||
.then(() => {})
|
||||
|
@ -54,7 +54,7 @@ export default abstract class WebapiPermissionCommandHandler {
|
|||
.values(
|
||||
permissions.map((p) => ({
|
||||
permission: p,
|
||||
apiId: webapiId,
|
||||
webapiId: webapiId,
|
||||
}))
|
||||
)
|
||||
.orIgnore()
|
||||
|
@ -87,7 +87,7 @@ export default abstract class WebapiPermissionCommandHandler {
|
|||
.into(webapiPermission)
|
||||
.values({
|
||||
permission: createPermission.permission,
|
||||
webapiId: createPermission.apiId,
|
||||
webapiId: createPermission.webapiId,
|
||||
})
|
||||
.execute()
|
||||
.then((result) => {
|
||||
|
@ -108,7 +108,7 @@ export default abstract class WebapiPermissionCommandHandler {
|
|||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(webapiPermission)
|
||||
.where("webapiId = :id", { id: deletePermission.apiId })
|
||||
.where("webapiId = :id", { id: deletePermission.webapiId })
|
||||
.andWhere("permission = :permission", { permission: deletePermission.permission })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue