Skip to content

Commit

Permalink
fix: Store did in cache for resources
Browse files Browse the repository at this point in the history
  • Loading branch information
DaevMithran committed Jan 10, 2025
1 parent 11e7875 commit e7adda8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/controllers/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class ResourceController {
check('alsoKnownAs.*.description').isString().withMessage(Messages.Invalid),
];
public static createResourceValidator = [
check('did').exists().isString().contains('did:cheqd').withMessage(Messages.InvalidDid),
check('did').optional().isString().contains('did:cheqd').withMessage(Messages.InvalidDid),
check('jobId')
.custom((value, { req }) => {
if (!value && !(req.body.name && req.body.type && req.body.content)) return false;
Expand All @@ -53,7 +53,7 @@ export class ResourceController {
check('alsoKnownAs.*.description').isString().withMessage(Messages.Invalid),
];
public static updateResourceValidator = [
check('did').exists().isString().contains('did:cheqd').withMessage(Messages.InvalidDid),
check('did').optional().isString().contains('did:cheqd').withMessage(Messages.InvalidDid),
check('jobId')
.custom((value, { req }) => {
if (!value && !(req.body.name && req.body.type && req.body.content)) return false;
Expand Down Expand Up @@ -87,7 +87,7 @@ export class ResourceController {
.json(Responses.GetInvalidResourceResponseV1({}, request.body.secret, result.array()[0].msg));
}

const { did } = request.params;
let { did } = request.params;
let {
jobId,
data,
Expand Down Expand Up @@ -129,6 +129,7 @@ export class ResourceController {
}

resourcePayload = storeData.resource;
did = storeData.did;
resourcePayload.data = new Uint8Array(Object.values(resourcePayload.data!));
} else if (!data) {
return response
Expand All @@ -153,7 +154,7 @@ export class ResourceController {
if (secret.signingResponse) {
signInputs = convertToSignInfo(secret.signingResponse);
} else {
LocalStore.instance.setResource(jobId, { resource: resourcePayload, state: IState.Action });
LocalStore.instance.setResource(jobId, { resource: resourcePayload, state: IState.Action, did });
return response
.status(200)
.json(
Expand Down Expand Up @@ -260,6 +261,7 @@ export class ResourceController {
}

resourcePayload = storeData.resource;
did = storeData.did;
resourcePayload.data = new Uint8Array(Object.values(resourcePayload.data!));
} else if (!content) {
return response
Expand Down Expand Up @@ -289,7 +291,7 @@ export class ResourceController {
if (secret.signingResponse) {
signInputs = convertToSignInfo(secret.signingResponse);
} else {
LocalStore.instance.setResource(jobId, { resource: resourcePayload, state: IState.Action });
LocalStore.instance.setResource(jobId, { resource: resourcePayload, state: IState.Action, did });
return response
.status(200)
.json(
Expand Down Expand Up @@ -376,6 +378,7 @@ export class ResourceController {
}

resourcePayload = storeData.resource;
did = storeData.did;
resourcePayload.data = new Uint8Array(Object.values(resourcePayload.data!));
} else if (!content) {
return response
Expand Down Expand Up @@ -447,7 +450,7 @@ export class ResourceController {
if (secret.signingResponse) {
signInputs = convertToSignInfo(secret.signingResponse);
} else {
LocalStore.instance.setResource(jobId, { resource: resourcePayload, state: IState.Action });
LocalStore.instance.setResource(jobId, { resource: resourcePayload, state: IState.Action, did });
return response
.status(200)
.json(
Expand Down
1 change: 1 addition & 0 deletions src/controllers/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ export interface IDidDocData {
export interface IResourceData {
resource: Partial<MsgCreateResourcePayload>;
state: IState;
did: string;
}

0 comments on commit e7adda8

Please sign in to comment.