Skip to content

Commit

Permalink
create secret approval data model
Browse files Browse the repository at this point in the history
  • Loading branch information
maidul98 committed Feb 13, 2023
1 parent edf0294 commit 0adc3d2
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions backend/src/models/secretApprovalRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import mongoose, { Schema, model } from 'mongoose';
import Secret, { ISecret } from './secret';

interface ISecretApprovalRequest {
secret: mongoose.Types.ObjectId;
requestedChanges: ISecret;
requestedBy: mongoose.Types.ObjectId;
approvers: IApprover[];
status: ApprovalStatus;
timestamp: Date;
requestType: RequestType;
requestId: string;
}

interface IApprover {
userId: mongoose.Types.ObjectId;
status: ApprovalStatus;
}

enum ApprovalStatus {
PENDING = 'pending',
APPROVED = 'approved',
REJECTED = 'rejected'
}

enum RequestType {
UPDATE = 'update',
DELETE = 'delete',
CREATE = 'create'
}

const approverSchema = new mongoose.Schema({
userId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true
},
status: {
type: String,
enum: [ApprovalStatus],
default: ApprovalStatus.PENDING
}
});


const secretApprovalRequestSchema = new Schema<ISecretApprovalRequest>(
{
secret: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Secret'
},
requestedChanges: Secret,
requestedBy: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
},
approvers: [approverSchema],
status: {
type: String,
enum: ApprovalStatus,
default: ApprovalStatus.PENDING
},
timestamp: {
type: Date,
default: Date.now
},
requestType: {
type: String,
enum: RequestType,
required: true
},
requestId: {
type: String,
required: false
}
},
{
timestamps: true
}
);

const SecretApprovalRequest = model<ISecretApprovalRequest>('SecretApprovalRequest', secretApprovalRequestSchema);

export default SecretApprovalRequest;

1 comment on commit 0adc3d2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report for backend

St.
Category Percentage Covered / Total
🟡 Statements 74.12% 63/85
🔴 Branches 0% 0/5
🔴 Functions 50% 1/2
🟡 Lines 75% 63/84

Test suite run success

1 tests passing in 1 suite.

Report generated by 🧪jest coverage report action from 0adc3d2

Please sign in to comment.