Browse Source

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

pull/8836/head
Ramesh Mane 3 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,
}),
{
count: await this.auditsService.auditCount({ baseId }),
count: await this.auditsService.auditCount({
query: req.query,
baseId,
}),
...req.query,
},
);

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

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

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

@ -9015,7 +9015,6 @@
"list": {
"type": "array",
"uniqueItems": true,
"minItems": 1,
"items": {
"$ref": "#/components/schemas/Audit"
}
@ -9061,6 +9060,61 @@
"in": "query",
"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"
}

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

@ -14110,7 +14110,6 @@
"list": {
"type": "array",
"uniqueItems": true,
"minItems": 1,
"items": {
"$ref": "#/components/schemas/Audit"
}
@ -14156,6 +14155,61 @@
"in": "query",
"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"
}

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

@ -74,14 +74,14 @@ export class AuditsService {
}
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 }) {
return await Audit.baseAuditList(param.sourceId, param.query);
async sourceAuditList(param: { query: any; sourceId: any }) {
return await Audit.sourceAuditList(param.sourceId, param.query);
}
async baseAuditCount(param: { sourceId: string }) {
return await Audit.baseAuditCount(param.sourceId);
async sourceAuditCount(param: { query: any; sourceId: string }) {
return await Audit.sourceAuditCount(param.sourceId);
}
}

Loading…
Cancel
Save