Browse Source

feat(nc-gui): add filter support in base audit list api

pull/8836/head
Ramesh Mane 5 months ago
parent
commit
c236e8169b
  1. 5
      packages/nocodb/src/controllers/audits.controller.ts
  2. 67
      packages/nocodb/src/models/Audit.ts
  3. 56
      packages/nocodb/src/schema/swagger-v2.json
  4. 56
      packages/nocodb/src/schema/swagger.json
  5. 10
      packages/nocodb/src/services/audits.service.ts

5
packages/nocodb/src/controllers/audits.controller.ts

@ -58,7 +58,10 @@ export class AuditsController {
baseId, baseId,
}), }),
{ {
count: await this.auditsService.auditCount({ baseId }), count: await this.auditsService.auditCount({
query: req.query,
baseId,
}),
...req.query, ...req.query,
}, },
); );

67
packages/nocodb/src/models/Audit.ts

@ -141,10 +141,23 @@ export default class Audit implements AuditType {
limit = 25, limit = 25,
offset = 0, offset = 0,
sourceId, sourceId,
user,
type,
startDate,
endDate,
orderBy,
}: { }: {
limit?: number; limit?: number;
offset?: number; offset?: number;
sourceId?: string; sourceId?: string;
user?: string;
type?: string;
startDate?: string;
endDate?: string;
orderBy?: {
created_at?: 'asc' | 'desc';
user?: 'asc' | 'desc';
};
}, },
) { ) {
return await Noco.ncMeta.metaList2( return await Noco.ncMeta.metaList2(
@ -155,9 +168,22 @@ export default class Audit implements AuditType {
condition: { condition: {
base_id: baseId, base_id: baseId,
...(sourceId ? { source_id: sourceId } : {}), ...(sourceId ? { source_id: sourceId } : {}),
...(user ? { user: user } : {}),
...(type ? { op_type: type } : {}),
}, },
orderBy: { orderBy: {
created_at: 'desc', ...(orderBy?.created_at
? { created_at: orderBy?.created_at }
: !orderBy?.user
? { created_at: 'desc' }
: {}),
...(orderBy?.user ? { user: orderBy?.user } : {}),
},
xcCondition: {
_and: [
...(startDate ? [{ created_at: { ge: startDate } }] : []),
...(endDate ? [{ created_at: { le: endDate } }] : []),
],
}, },
limit, limit,
offset, offset,
@ -167,18 +193,39 @@ export default class Audit implements AuditType {
static async baseAuditCount( static async baseAuditCount(
baseId: string, baseId: string,
sourceId?: string, {
sourceId,
user,
type,
startDate,
endDate,
}: {
sourceId?: string;
user?: string;
type?: string;
startDate?: string;
endDate?: string;
},
): Promise<number> { ): Promise<number> {
return ( return await Noco.ncMeta.metaCount(
await Noco.ncMeta RootScopes.ROOT,
.knex(MetaTable.AUDIT) RootScopes.ROOT,
.where({ MetaTable.AUDIT,
{
condition: {
base_id: baseId, base_id: baseId,
...(user ? { user: user } : {}),
...(sourceId ? { source_id: sourceId } : {}), ...(sourceId ? { source_id: sourceId } : {}),
}) ...(type ? { op_type: type } : {}),
.count('id', { as: 'count' }) },
.first() xcCondition: {
)?.count; _and: [
...(startDate ? [{ created_at: { ge: startDate } }] : []),
...(endDate ? [{ created_at: { le: endDate } }] : []),
],
},
},
);
} }
static async sourceAuditList(sourceId: string, { limit = 25, offset = 0 }) { static async sourceAuditList(sourceId: string, { limit = 25, offset = 0 }) {

56
packages/nocodb/src/schema/swagger-v2.json

@ -9015,7 +9015,6 @@
"list": { "list": {
"type": "array", "type": "array",
"uniqueItems": true, "uniqueItems": true,
"minItems": 1,
"items": { "items": {
"$ref": "#/components/schemas/Audit" "$ref": "#/components/schemas/Audit"
} }
@ -9061,6 +9060,61 @@
"in": "query", "in": "query",
"name": "sourceId" "name": "sourceId"
}, },
{
"schema": {
"type": "string"
},
"in": "query",
"name": "user"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "type"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "startDate"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "endDate"
},
{
"schema": {
"properties": {
"created_at": {
"type": "string",
"description": "Sort direction",
"enum": [
"asc",
"desc"
],
"example": "desc"
},
"user": {
"type": "string",
"description": "Sort direction",
"enum": [
"asc",
"desc"
],
"example": "desc"
}
},
"type": "object"
},
"in": "query",
"name": "orderBy"
},
{ {
"$ref": "#/components/parameters/xc-auth" "$ref": "#/components/parameters/xc-auth"
} }

56
packages/nocodb/src/schema/swagger.json

@ -14110,7 +14110,6 @@
"list": { "list": {
"type": "array", "type": "array",
"uniqueItems": true, "uniqueItems": true,
"minItems": 1,
"items": { "items": {
"$ref": "#/components/schemas/Audit" "$ref": "#/components/schemas/Audit"
} }
@ -14156,6 +14155,61 @@
"in": "query", "in": "query",
"name": "sourceId" "name": "sourceId"
}, },
{
"schema": {
"type": "string"
},
"in": "query",
"name": "user"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "type"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "startDate"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "endDate"
},
{
"schema": {
"properties": {
"created_at": {
"type": "string",
"description": "Sort direction",
"enum": [
"asc",
"desc"
],
"example": "desc"
},
"user": {
"type": "string",
"description": "Sort direction",
"enum": [
"asc",
"desc"
],
"example": "desc"
}
},
"type": "object"
},
"in": "query",
"name": "orderBy"
},
{ {
"$ref": "#/components/parameters/xc-auth" "$ref": "#/components/parameters/xc-auth"
} }

10
packages/nocodb/src/services/audits.service.ts

@ -74,14 +74,14 @@ export class AuditsService {
} }
async auditCount(param: { query?: any; baseId: string }) { async auditCount(param: { query?: any; baseId: string }) {
return await Audit.baseAuditCount(param.baseId, param.query?.sourceId); return await Audit.baseAuditCount(param.baseId, param.query);
} }
async baseAuditList(param: { query: any; sourceId: any }) { async sourceAuditList(param: { query: any; sourceId: any }) {
return await Audit.baseAuditList(param.sourceId, param.query); return await Audit.sourceAuditList(param.sourceId, param.query);
} }
async baseAuditCount(param: { sourceId: string }) { async sourceAuditCount(param: { query: any; sourceId: string }) {
return await Audit.baseAuditCount(param.sourceId); return await Audit.sourceAuditCount(param.sourceId);
} }
} }

Loading…
Cancel
Save