fix(test): Add ENCRYPTION_KEY to bridge.module.spec.ts and fix API lint errors
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
This commit is contained in:
@@ -9,6 +9,7 @@ import type {
|
||||
CreateCredentialDto,
|
||||
UpdateCredentialDto,
|
||||
QueryCredentialDto,
|
||||
QueryCredentialAuditDto,
|
||||
CredentialResponseDto,
|
||||
PaginatedCredentialsDto,
|
||||
CredentialValueResponseDto,
|
||||
@@ -367,6 +368,114 @@ export class CredentialsService {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get credential audit logs with filters and pagination
|
||||
* Returns all credential-related activities for the workspace
|
||||
* RLS ensures users only see their own workspace activities
|
||||
*/
|
||||
async getAuditLog(
|
||||
workspaceId: string,
|
||||
query: QueryCredentialAuditDto
|
||||
): Promise<{
|
||||
data: {
|
||||
id: string;
|
||||
action: ActivityAction;
|
||||
entityId: string;
|
||||
createdAt: Date;
|
||||
details: Record<string, unknown>;
|
||||
user: {
|
||||
id: string;
|
||||
name: string | null;
|
||||
email: string;
|
||||
};
|
||||
}[];
|
||||
meta: {
|
||||
total: number;
|
||||
page: number;
|
||||
limit: number;
|
||||
totalPages: number;
|
||||
};
|
||||
}> {
|
||||
const page = query.page ?? 1;
|
||||
const limit = query.limit ?? 20;
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
// Build where clause
|
||||
const where: Prisma.ActivityLogWhereInput = {
|
||||
workspaceId,
|
||||
entityType: EntityType.CREDENTIAL,
|
||||
};
|
||||
|
||||
// Filter by specific credential if provided
|
||||
if (query.credentialId) {
|
||||
where.entityId = query.credentialId;
|
||||
}
|
||||
|
||||
// Filter by action if provided
|
||||
if (query.action) {
|
||||
where.action = query.action;
|
||||
}
|
||||
|
||||
// Filter by date range if provided
|
||||
if (query.startDate || query.endDate) {
|
||||
where.createdAt = {};
|
||||
if (query.startDate) {
|
||||
where.createdAt.gte = query.startDate;
|
||||
}
|
||||
if (query.endDate) {
|
||||
where.createdAt.lte = query.endDate;
|
||||
}
|
||||
}
|
||||
|
||||
// Execute queries in parallel
|
||||
const [data, total] = await Promise.all([
|
||||
this.prisma.activityLog.findMany({
|
||||
where,
|
||||
select: {
|
||||
id: true,
|
||||
action: true,
|
||||
entityId: true,
|
||||
createdAt: true,
|
||||
details: true,
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
email: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
skip,
|
||||
take: limit,
|
||||
}),
|
||||
this.prisma.activityLog.count({ where }),
|
||||
]);
|
||||
|
||||
return {
|
||||
data: data as {
|
||||
id: string;
|
||||
action: ActivityAction;
|
||||
entityId: string;
|
||||
createdAt: Date;
|
||||
details: Record<string, unknown>;
|
||||
user: {
|
||||
id: string;
|
||||
name: string | null;
|
||||
email: string;
|
||||
};
|
||||
}[],
|
||||
meta: {
|
||||
total,
|
||||
page,
|
||||
limit,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get select fields for credential responses
|
||||
* NEVER includes encryptedValue
|
||||
|
||||
Reference in New Issue
Block a user