Skip to content

Commit 2b88f3d

Browse files
paulbertdogi
andauthored
all: smoother rule consistent type asserting (connects #9082) (#9853)
Co-authored-by: dogi <dogi@users.noreply.github.com>
1 parent 89c3184 commit 2b88f3d

7 files changed

Lines changed: 36 additions & 14 deletions

File tree

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"@angular-eslint/use-pipe-transform-interface": "error",
8787
"@typescript-eslint/adjacent-overload-signatures": "error",
8888
"@typescript-eslint/array-type": "off",
89-
// "@typescript-eslint/consistent-type-assertions": "error",
89+
"@typescript-eslint/consistent-type-assertions": "error",
9090
// "@typescript-eslint/member-ordering": "error",
9191
// "@typescript-eslint/naming-convention": [
9292
// "error",

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export default defineConfig([globalIgnores(["projects/**/*", "chatapi/**/*"]), {
8787
"@angular-eslint/use-pipe-transform-interface": "error",
8888
"@typescript-eslint/adjacent-overload-signatures": "error",
8989
"@typescript-eslint/array-type": "off",
90+
"@typescript-eslint/consistent-type-assertions": "error",
9091
"@typescript-eslint/no-empty-function": "off",
9192
"@typescript-eslint/no-empty-interface": "error",
9293
"@typescript-eslint/no-explicit-any": "off",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "planet",
33
"license": "AGPL-3.0",
4-
"version": "0.22.45",
4+
"version": "0.22.46",
55
"myplanet": {
66
"latest": "v0.53.33",
77
"min": "v0.51.90"

src/app/exams/exams-add.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ export class ExamsAddComponent implements OnInit, CanComponentDeactivate {
8989
documentInfo: ExamDocumentInfo = {};
9090
pageType: 'Add' | 'Update' | 'Copy' = 'Add';
9191
courseName = '';
92-
examType: 'exam' | 'survey' = <'exam' | 'survey'>this.route.snapshot.paramMap.get('type') || 'exam';
92+
examType: 'exam' | 'survey';
9393
teamId = this.route.parent?.snapshot.paramMap.get('teamId') || null;
94-
successMessage = this.examType === 'survey' ? $localize`New survey added` : $localize`New test added`;
94+
successMessage: string;
9595
steps = [];
9696
showFormError = false;
9797
showPreviewError = false;
@@ -127,6 +127,9 @@ export class ExamsAddComponent implements OnInit, CanComponentDeactivate {
127127
private dialog: MatDialog,
128128
private submissionsService: SubmissionsService
129129
) {
130+
const typeParam = this.route.snapshot.paramMap.get('type');
131+
this.examType = typeParam === 'exam' || typeParam === 'survey' ? typeParam : 'exam';
132+
this.successMessage = this.examType === 'survey' ? $localize`New survey added` : $localize`New test added`;
130133
this.createForm();
131134
}
132135

src/app/shared/forms/planet-markdown-textbox.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ export class PlanetMarkdownTextboxComponent implements ControlValueAccessor, DoC
249249
this.editor.options.insertTexts.image = [ markdown, '' ];
250250
this.editor.easyMDE.drawImage();
251251
this.value = {
252-
...<ValueWithImages>this._value,
253-
images: [ ...(<ValueWithImages>this._value).images, { resourceId: image._id, filename: image.filename, markdown } ]
252+
...this._value as ValueWithImages,
253+
images: [ ...(this._value as ValueWithImages).images, { resourceId: image._id, filename: image.filename, markdown } ]
254254
};
255255
}
256256
});

src/app/submissions/submissions.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ export class SubmissionsService {
312312
...submission,
313313
teamInfo: submission.team ? { name: submission.team.name, type: submission.team.type } : null
314314
}));
315-
return <[any[], number, string[]]>[submissionsWithTeamInfo, time, questionTexts];
315+
return [submissionsWithTeamInfo, time, questionTexts] as [any[], number, string[]];
316316
}),
317317
tap(([ updatedSubmissions, time, questionTexts ]: [any[], number, string[]]) => {
318318
const title = `${toProperCase($localize`${type}`)} - ${$localize`${exam.name}`} (${updatedSubmissions.length})`;
@@ -502,7 +502,7 @@ export class SubmissionsService {
502502
planetName: codeToPlanetName(submission.source, this.stateService.configuration, planetsWithName),
503503
teamInfo: submission.team ? { name: submission.team.name, type: submission.team.type } : null
504504
}));
505-
return <[any[], number, string[]]>[submissionsWithPlanetName, time, questionTexts];
505+
return [submissionsWithPlanetName, time, questionTexts] as [any[], number, string[]];
506506
})
507507
).subscribe(async tuple => {
508508
if (!tuple) {

src/app/teams/teams-reports.component.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ import { MatCard, MatCardHeader, MatCardTitle, MatCardSubtitle, MatCardContent,
2222
import { TeamsReportsDetailComponent } from './teams-reports-detail.component';
2323
import { MatIcon } from '@angular/material/icon';
2424

25+
interface NewReportForm {
26+
_id?: string,
27+
_rev?: string,
28+
beginningBalance: string,
29+
description: string,
30+
endDate: Date,
31+
otherExpenses: number,
32+
otherIncome: number,
33+
sales: number,
34+
startDate: Date,
35+
wages: string
36+
}
37+
2538
@Component({
2639
selector: 'planet-teams-reports',
2740
styleUrls: ['./teams-reports.scss'],
@@ -153,18 +166,23 @@ export class TeamsReportsComponent implements DoCheck {
153166
() => {};
154167
}
155168

156-
updateReport(oldReport, newReport: any = {}) {
169+
updateReport(oldReport, newReport: NewReportForm | {} = {}) {
157170
const dateFields = [ 'startDate', 'endDate' ];
158171
const numberFields = [ 'beginningBalance', 'sales', 'otherIncome', 'wages', 'otherExpenses' ];
159-
const transformFields = (key: string, value: Date | string) => dateFields.indexOf(key) > -1 ?
160-
(<Date>value).getTime() :
172+
const transformFields = (key: string, value: string | Date | number) => dateFields.indexOf(key) > -1 ?
173+
(value as Date).getTime() :
161174
numberFields.indexOf(key) > -1 ?
162175
+value :
163176
value;
164-
const { _id, _rev, ...newDoc } = <any>Object.entries(newReport).reduce(
165-
(obj, [ key, value ]: [ string, Date | string ]) => ({ ...obj, [key]: transformFields(key, value) }),
177+
const { _id, _rev, ...newDoc } = Object.entries(newReport).reduce(
178+
(obj, [ key, value ]: [ string, string | Date | number ]) => {
179+
return {
180+
...obj,
181+
[key]: transformFields(key, value)
182+
};
183+
},
166184
{}
167-
);
185+
) as any;
168186
const docs = [ { ...oldReport, status: 'archived' }, newDoc ].filter(doc => doc.startDate !== undefined);
169187
return this.teamsService.updateAdditionalDocs(docs, this.team, 'report', { utcKeys: dateFields }).pipe(tap(() => {
170188
this.reportsChanged.emit();

0 commit comments

Comments
 (0)