Skip to content

Commit

Permalink
Implement member retrieval by login, enhance recent surveys query, an…
Browse files Browse the repository at this point in the history
…d add kudos update functionality
  • Loading branch information
MattG57 committed Dec 4, 2024
1 parent 1611030 commit 3d5a946
Show file tree
Hide file tree
Showing 12 changed files with 473 additions and 100 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"start": "node --enable-source-maps dist/index.js | bunyan -o short -l info",
"test": "jest",
"build": "tsc",
"dev": "tsx watch src/index.ts | bunyan -o short -l debug",
"dev": "tsx watch src/index.ts | bunyan -o short -l info",
"lint": "eslint src/**/*.ts",
"db:start": "docker-compose -f ../compose.yml up -d db",
"dotenv": "cp -n .env.example .env || true"
Expand Down
22 changes: 21 additions & 1 deletion backend/src/controllers/survey.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SurveyController {

async getRecentSurveysWithGoodReasons(req: Request, res: Response): Promise<void> {
try {
const minReasonLength = parseInt(req.query.minReasonLength as string) || 20;
const minReasonLength = parseInt(req.params.minReasonLength, 10) || 20;
const surveys = await surveyService.getRecentSurveysWithGoodReasons(minReasonLength);
res.status(200).json(surveys);
} catch (error) {
Expand Down Expand Up @@ -120,6 +120,26 @@ class SurveyController {
}
}

async updateKudos(req: Request, res: Response): Promise<void> {
try {
const { id } = req.params;

const survey = await Survey.findByPk(id);
if (!survey) {
res.status(404).json({ error: 'Survey not found' });
return;
}

survey.kudos = (survey.kudos || 0) + 1;
await survey.save();

res.status(200).json(survey);
} catch (error) {
console.log(error);
res.status(500).json(error);
}
}

async deleteSurvey(req: Request, res: Response): Promise<void> {
try {
const { id } = req.params;
Expand Down
18 changes: 18 additions & 0 deletions backend/src/controllers/teams.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ class TeamsController {
res.status(500).json(error);
}
}

async getMemberByLogin(req: Request, res: Response): Promise<void> {
try {
const { login } = req.params;
const member = await Member.findOne({
where: { login },
attributes: ['login', 'name', 'url', 'avatar_url']
});

if (member) {
res.json(member);
} else {
res.status(404).json({ message: 'User not found' });
}
} catch (error) {
res.status(500).json(error);
}
}
}

export default new TeamsController();
2 changes: 1 addition & 1 deletion backend/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Database {
sequelize?: Sequelize;
options: Options = {
dialect: 'mysql',
logging: (sql) => logger.debug(sql),
logging: (sql) => logger.error(sql),
timezone: '+00:00', // Force UTC timezone
dialectOptions: {
timezone: '+00:00' // Force UTC for MySQL connection
Expand Down
2 changes: 2 additions & 0 deletions backend/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ router.put('/survey/:id', surveyController.updateSurvey); // put github survey l
router.delete('/survey/:id', surveyController.deleteSurvey);
router.get('/survey/recent-good-reasons/:minReasonLength', surveyController.getRecentSurveysWithGoodReasons);
router.put('/survey/:id/github', surveyController.updateSurveyGitHub);
router.put('/survey/kudos/:id', surveyController.updateKudos);

router.get('/usage', usageController.getUsage);

Expand All @@ -34,6 +35,7 @@ router.get('/seats/:id', SeatsController.getSeat);

router.get('/teams', teamsController.getAllTeams);
router.get('/members', teamsController.getAllMembers);
router.get('/members/:login', teamsController.getMemberByLogin);

router.get('/settings', settingsController.getAllSettings);
router.post('/settings', settingsController.createSettings);
Expand Down
11 changes: 7 additions & 4 deletions backend/src/services/survey.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ class SurveyService {
return await Survey.findByPk(survey.id);
}

async getRecentSurveysWithGoodReasons(minReasonLength: number = 20) {
return await Survey.findAll({

async getRecentSurveysWithGoodReasons(minReasonLength: number): Promise<Survey[]> {
return Survey.findAll({
where: {
reason: {
[Op.and]: [
{ [Op.ne]: null },
{ [Op.length]: { [Op.gt]: minReasonLength } }
{ [Op.ne]: '' },
{ [Op.gte]: minReasonLength }
]
}
},
order: [['updatedAt', 'DESC']]
order: [['updatedAt', 'DESC']],
limit: 20
});
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/* Core Layout */
.page-container {
max-width: 1000px;
margin: 0 auto;
padding: 1.5rem;
}

.two-column-layout {
display: grid;
grid-template-columns: 3fr 2fr;
gap: 2rem;
align-items: start;
}

/* Typography & Questions */
.page-header {
margin-bottom: 2rem;
}

.page-header h2 {
font-size: 1.75rem;
font-weight: 600;
color: #1a202c;
margin: 0;
}

.page-header h4 {
font-size: 1rem;
color: #718096;
margin: 0.25rem 0 0;
}

.conditional-fields {
border: 1px solid #e2e8f0;
border-radius: 8px;
padding: 1.25rem;
margin-bottom: 1.5rem;
}

/* Numbered Questions */
.question {
position: relative;
padding-left: 2rem;
margin: 1.5rem 0;
}

.question::before {
content: attr(data-number);
position: absolute;
left: 0;
color: #4a5568;
font-weight: 500;
}

/* Form Elements */
.example-form-field {
width: 100%;
margin-bottom: 1rem;
}

.reason-label {
font-size: 0.875rem;
color: #4a5568;
margin-top: 0.5rem;
}

/* Radio & Slider */
.example-radio-group {
display: flex;
flex-direction: column;
gap: 0.75rem;
}

.slider-labels-container {
width: 95%;
margin: 0 8px;
}

/* Insights Card */
.scrollable-card {
background: white;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.scrollable-card-content div {
padding: 0.75rem;
border-bottom: 1px solid #e2e8f0;
}

/* Submit Button */
button[type="submit"] {
width: 100%;
padding: 0.75rem;
font-size: 1rem;
margin-top: 1rem;
background: #4299e1;
color: white;
border-radius: 6px;
}

.example-mat-slider {
width: 100%;
}


.slider-labels-container {
display: inline-block;
margin: 0 5px;
width: 90%;
.slider-labels {
display: block;
width: 90%;
height: 12px;
margin-top: -10px;
position: relative;
margin-bottom: 18px;
> * {
position: relative;
transform: translateX(-40%);
}
}
}

.small-icon {
font-size: 20px; // Adjust the size as needed
}


@keyframes scroll {
0% {
transform: translateY(0);
}
100% {
transform: translateY(-50%);
}
}


.scrollable-card {
max-height: 600px; /* Increase the maximum height for the card */
overflow: hidden; /* Hide the scrollbar */
white-space: normal; /* Ensure text wraps properly */
position: relative;
margin-top: 20px; /* Add margin to separate from the header */
}

.scrollable-card-content {
position: relative;
animation: scroll 20s linear infinite; /* Adjust duration as needed */
padding-top: 60px; /* Add padding to ensure content does not overlap with the title */
}

.scrollable-card-content:hover {
animation-play-state: paused; /* Pause animation on hover */
}

.scrollable-card-content div {
margin-bottom: 3em; /* Add extra space between reasons */
}

.kudos-count {
font-size: 0.9em; // Reduced by 2 points
margin-left: 5px;
}
Loading

0 comments on commit 3d5a946

Please sign in to comment.