Skip to content

Commit 9e7ff81

Browse files
committed
dependency cycle warnings for APIKey and AWS/project controllers
1 parent 19f9ed7 commit 9e7ff81

File tree

4 files changed

+38
-13
lines changed

4 files changed

+38
-13
lines changed

client/modules/User/components/APIKeyList.jsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import React from 'react';
33
import { orderBy } from 'lodash';
44
import { useTranslation } from 'react-i18next';
55

6-
import { APIKeyPropType } from './APIKeyForm';
7-
86
import dates from '../../../utils/formatDate';
97
import TrashCanIcon from '../../../images/trash-can.svg';
108

@@ -49,8 +47,26 @@ function APIKeyList({ apiKeys, onRemove }) {
4947
}
5048

5149
APIKeyList.propTypes = {
52-
apiKeys: PropTypes.arrayOf(PropTypes.shape(APIKeyPropType)).isRequired,
50+
apiKeys: PropTypes.arrayOf(
51+
PropTypes.shape({
52+
id: PropTypes.string.isRequired,
53+
token: PropTypes.string,
54+
label: PropTypes.string.isRequired,
55+
createdAt: PropTypes.string.isRequired,
56+
lastUsedAt: PropTypes.string
57+
})
58+
),
5359
onRemove: PropTypes.func.isRequired
5460
};
5561

62+
APIKeyList.defaultProps = {
63+
apiKeys: PropTypes.arrayOf(
64+
PropTypes.shape({
65+
id: 0,
66+
label: 'api-key',
67+
createdAt: new Date()
68+
})
69+
)
70+
};
71+
5672
export default APIKeyList;

server/controllers/aws.controller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
DeleteObjectsCommand
99
} from '@aws-sdk/client-s3';
1010
import mongoose from 'mongoose';
11-
import { getProjectsForUserId } from './project.controller';
1211
import User from '../models/user';
12+
import Project from '../models/project';
1313

1414
const { ObjectId } = mongoose.Types;
1515

@@ -194,7 +194,7 @@ export async function listObjectsInS3ForUser(userId) {
194194
size: object.Size
195195
}));
196196

197-
const projects = await getProjectsForUserId(userId);
197+
const projects = await Project.getProjectsForUserId(userId);
198198
const projectAssets = [];
199199
let totalSize = 0;
200200

server/controllers/project.controller.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,6 @@ export async function getProject(req, res) {
100100
return res.json(project);
101101
}
102102

103-
export function getProjectsForUserId(userId) {
104-
return Project.find({ user: userId })
105-
.sort('-createdAt')
106-
.select('name files id createdAt updatedAt')
107-
.exec();
108-
}
109-
110103
export async function getProjectAsset(req, res) {
111104
const projectId = req.params.project_id;
112105
const project = await Project.findOne({
@@ -141,7 +134,7 @@ export async function getProjectAsset(req, res) {
141134

142135
export async function getProjects(req, res) {
143136
if (req.user) {
144-
const projects = await getProjectsForUserId(req.user._id);
137+
const projects = await Project.getProjectsForUserId(req.user._id);
145138
res.json(projects);
146139
} else {
147140
// could just move this to client side

server/models/project.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,21 @@ projectSchema.methods.isSlugUnique = async function isSlugUnique() {
7676
};
7777
};
7878

79+
/**
80+
* Queries Project collection by userId and returns all Projects that match.
81+
* @return {Promise<{ isUnique: boolean; conflictingIds: string[] }>}
82+
*/
83+
projectSchema.static.getProjectsForUserId = async function getProjectsForUserId(
84+
userId
85+
) {
86+
const project = this;
87+
88+
return project
89+
.find({ user: userId })
90+
.sort('-createdAt')
91+
.select('name files id createdAt updatedAt')
92+
.exec();
93+
};
94+
7995
export default mongoose.models.Project ||
8096
mongoose.model('Project', projectSchema);

0 commit comments

Comments
 (0)