gadget/gadget-code/src/models/api-client-log.ts
2026-05-01 14:47:18 -04:00

41 lines
991 B
TypeScript

// src/models/api-client-log.ts
// Copyright (C) 2026 Robert Colbert <rob.colbert@openplatform.us>
// All Rights Reserved
import { Schema, model } from "mongoose";
import { IApiClient } from "./api-client.js";
import { GadgetId } from "@gadget/api";
import { nanoid } from "nanoid";
export interface IApiClientLog {
_id: GadgetId;
client: IApiClient | GadgetId;
createdAt: Date;
method: string;
url: string;
}
export const ApiClientLogSchema = new Schema<IApiClientLog>({
_id: { type: String, default: () => nanoid() },
client: { type: String, required: true, index: 1, ref: "ApiClient" },
createdAt: {
type: Date,
default: Date.now,
required: true,
index: -1,
expires: "30d",
},
method: { type: String, required: true },
url: { type: String, required: true },
});
export const ApiClientLog = model<IApiClientLog>(
"ApiClientLog",
ApiClientLogSchema,
);
export default ApiClientLog;
(async () => {
await ApiClientLog.syncIndexes();
})();