Skip to content

Commit

Permalink
dependency cycle warnings for APIKey and AWS/project controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
raclim committed Oct 5, 2024
1 parent 19f9ed7 commit 9e7ff81
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
22 changes: 19 additions & 3 deletions client/modules/User/components/APIKeyList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import React from 'react';
import { orderBy } from 'lodash';
import { useTranslation } from 'react-i18next';

import { APIKeyPropType } from './APIKeyForm';

import dates from '../../../utils/formatDate';
import TrashCanIcon from '../../../images/trash-can.svg';

Expand Down Expand Up @@ -49,8 +47,26 @@ function APIKeyList({ apiKeys, onRemove }) {
}

APIKeyList.propTypes = {
apiKeys: PropTypes.arrayOf(PropTypes.shape(APIKeyPropType)).isRequired,
apiKeys: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string.isRequired,
token: PropTypes.string,
label: PropTypes.string.isRequired,
createdAt: PropTypes.string.isRequired,
lastUsedAt: PropTypes.string
})
),
onRemove: PropTypes.func.isRequired
};

APIKeyList.defaultProps = {
apiKeys: PropTypes.arrayOf(
PropTypes.shape({
id: 0,
label: 'api-key',
createdAt: new Date()
})
)
};

export default APIKeyList;
4 changes: 2 additions & 2 deletions server/controllers/aws.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
DeleteObjectsCommand
} from '@aws-sdk/client-s3';
import mongoose from 'mongoose';
import { getProjectsForUserId } from './project.controller';
import User from '../models/user';
import Project from '../models/project';

const { ObjectId } = mongoose.Types;

Expand Down Expand Up @@ -194,7 +194,7 @@ export async function listObjectsInS3ForUser(userId) {
size: object.Size
}));

const projects = await getProjectsForUserId(userId);
const projects = await Project.getProjectsForUserId(userId);
const projectAssets = [];
let totalSize = 0;

Expand Down
9 changes: 1 addition & 8 deletions server/controllers/project.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,6 @@ export async function getProject(req, res) {
return res.json(project);
}

export function getProjectsForUserId(userId) {
return Project.find({ user: userId })
.sort('-createdAt')
.select('name files id createdAt updatedAt')
.exec();
}

export async function getProjectAsset(req, res) {
const projectId = req.params.project_id;
const project = await Project.findOne({
Expand Down Expand Up @@ -141,7 +134,7 @@ export async function getProjectAsset(req, res) {

export async function getProjects(req, res) {
if (req.user) {
const projects = await getProjectsForUserId(req.user._id);
const projects = await Project.getProjectsForUserId(req.user._id);
res.json(projects);
} else {
// could just move this to client side
Expand Down
16 changes: 16 additions & 0 deletions server/models/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,21 @@ projectSchema.methods.isSlugUnique = async function isSlugUnique() {
};
};

/**
* Queries Project collection by userId and returns all Projects that match.
* @return {Promise<{ isUnique: boolean; conflictingIds: string[] }>}
*/
projectSchema.static.getProjectsForUserId = async function getProjectsForUserId(
userId
) {
const project = this;

return project
.find({ user: userId })
.sort('-createdAt')
.select('name files id createdAt updatedAt')
.exec();
};

export default mongoose.models.Project ||
mongoose.model('Project', projectSchema);

0 comments on commit 9e7ff81

Please sign in to comment.