Skip to content
Open
10 changes: 6 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -630,11 +630,13 @@ state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
Copyright (C) 2024 GigaMeter

GigaMeter is a client desktop application that can be installed on Windows that automatically measures the internet upload and download speed of a network using minimal data.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
Expand All @@ -658,4 +660,4 @@ specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<https://www.gnu.org/licenses/>.
<https://www.gnu.org/licenses/>.
11 changes: 11 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
NOTICE

This project, GigaMeter, uses tools, data, and resources provided by Measurement Lab (M-Lab).

Measurement Lab (M-Lab) is an open and transparent platform for global measurement of internet performance. M-Lab is a fiscally sponsored project of Code for Science & Society (CS&S).

The tools and data utilized in this project are made available under the No Rights Reserved Creative Commons Zero Waiver License. Attribution is provided to Measurement Lab for their contributions.

For more information about M-Lab, visit https://www.measurementlab.net/.

The M-Lab NDT Data Set 2009-02-11–2024-12-31. https://measurementlab.net/tests/ndt
3 changes: 3 additions & 0 deletions src/admin/admin.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export class AdminSchoolDto {
@ApiProperty()
is_blocked: boolean;

@ApiProperty()
email: string[];

@ApiProperty()
created_at: Date;
}
1 change: 1 addition & 0 deletions src/admin/admin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class AdminService {
ip_address: school.ip_address,
country_code: school.country_code,
is_blocked: school.is_blocked,
email: Array.isArray(school.email) ? school.email : [school.email],
created_at: school.created_at,
};
}
Expand Down
18 changes: 12 additions & 6 deletions src/common/mock-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,30 @@ export const mockAdminSchoolDto: AdminSchoolDto[] = [
id: 1,
user_id: 'test_id1',
giga_id_school: 'gigaid1',
mac_address: 'string',
mac_address: 'string1',
os: 'string',
app_version: 'string',
created: 'string',
network_information: null,
ip_address: 'string',
country_code: 'string',
is_blocked: false,
email: ['test@test.com'],
created_at: new Date('2024-04-12T04:13:37.300Z'),
},
{
id: 2,
user_id: 'test_id',
giga_id_school: 'gigaid2',
mac_address: 'string',
mac_address: 'string2',
os: 'string',
app_version: 'string',
created: 'string',
network_information: null,
ip_address: 'string',
country_code: 'string',
is_blocked: true,
email: ['test@test.com'],
created_at: new Date('2024-04-12T04:14:03.650Z'),
},
];
Expand All @@ -95,28 +97,30 @@ export const mockSchoolDto: SchoolDto[] = [
id: '1',
user_id: 'test_id1',
giga_id_school: 'gigaid1',
mac_address: 'string',
mac_address: 'string3',
os: 'string',
app_version: 'string',
created: 'string',
network_information: null,
ip_address: 'string',
country_code: 'string',
is_blocked: false,
email: ['test@test.com'],
created_at: new Date('2024-04-12T04:13:37.300Z'),
},
{
id: '2',
user_id: 'test_id',
giga_id_school: 'gigaid2',
mac_address: 'string',
mac_address: 'string4',
os: 'string',
app_version: 'string',
created: 'string',
network_information: null,
ip_address: 'string',
country_code: 'string',
is_blocked: true,
email: ['test@test.com'],
created_at: new Date('2024-04-12T04:14:03.650Z'),
},
];
Expand All @@ -126,7 +130,7 @@ export const mockSchoolModel = [
id: toBigInt(1),
user_id: 'test_id1',
giga_id_school: 'gigaid1',
mac_address: 'string',
mac_address: 'string5',
os: 'string',
app_version: 'string',
created: 'string',
Expand All @@ -135,13 +139,14 @@ export const mockSchoolModel = [
country_code: 'string',
is_blocked: false,
notify: true,
email: ['test@test.com'],
created_at: new Date('2024-04-12T04:13:37.300Z'),
},
{
id: toBigInt(2),
user_id: 'test_id',
giga_id_school: 'gigaid2',
mac_address: 'string',
mac_address: 'string6',
os: 'string',
app_version: 'string',
created: 'string',
Expand All @@ -150,6 +155,7 @@ export const mockSchoolModel = [
country_code: 'string',
is_blocked: true,
notify: false,
email: ['test@test.com'],
created_at: new Date('2024-04-12T04:14:03.650Z'),
},
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
Warnings:

- A unique constraint covering the columns `[mac_address]` on the table `dailycheckapp_school` will be added. If there are existing duplicate values, this will fail.

*/
-- AlterTable
ALTER TABLE "dailycheckapp_school" ADD COLUMN "email" TEXT[];

-- CreateIndex
CREATE UNIQUE INDEX "dailycheckapp_school_mac_address_key" ON "dailycheckapp_school"("mac_address");
3 changes: 2 additions & 1 deletion src/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ model dailycheckapp_school {
id BigInt @id @default(autoincrement())
user_id String?
giga_id_school String?
mac_address String?
mac_address String? @unique
os String?
app_version String?
created String?
Expand All @@ -60,6 +60,7 @@ model dailycheckapp_school {
country_code String?
is_blocked Boolean @default(false)
notify Boolean @default(false)
email String[]
created_at DateTime? @default(dbgenerated("(CURRENT_TIMESTAMP AT TIME ZONE 'UTC'::text)")) @db.Timestamptz(6)
}

Expand Down
27 changes: 27 additions & 0 deletions src/school/school.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
HttpStatus,
Param,
Post,
Put,
Query,
UseGuards,
} from '@nestjs/common';
Expand Down Expand Up @@ -316,4 +317,30 @@ export class SchoolController {
message: 'success',
};
}

@Put()
@ApiOperation({
summary: 'Update a school in the Giga Meter database',
})
@ApiResponse({
status: 201,
description: 'Returns Id and mac address of school updated',
type: String,
})
@ApiResponse({
status: 401,
description: 'Unauthorized; Invalid api key provided',
})
async updateSchool(
@Body() schoolDto: SchoolDto,
Comment thread
rashan-smith marked this conversation as resolved.
Outdated
): Promise<ApiSuccessResponseDto<AddRecordResponseDto>> {
const schoolId = await this.schoolService.updateSchool(schoolDto);

return {
success: true,
data: { user_id: schoolId },
timestamp: new Date().toISOString(),
message: 'success',
};
}
}
3 changes: 3 additions & 0 deletions src/school/school.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export class SchoolDto {
@ApiProperty()
is_blocked: boolean;

@ApiProperty()
email: string[];

@ApiProperty()
created_at: Date;
}
Expand Down
25 changes: 22 additions & 3 deletions src/school/school.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,20 @@ export class SchoolService {
return school.user_id;
}

private toDto(school: School): SchoolDto {
async updateSchool(schoolDto: SchoolDto): Promise<string> {
const model = await this.toModel(schoolDto);
const existingSchool = await this.prisma.dailycheckapp_school.findFirst({
where: { mac_address: schoolDto.mac_address, user_id: schoolDto.user_id }
});

const school = await this.prisma.dailycheckapp_school.update({
where: { mac_address: existingSchool.mac_address, user_id: existingSchool.user_id },
data: model
});
return school.user_id;
}

private async toDto(school: School): Promise<SchoolDto> {
return {
id: school.id.toString(),
user_id: school.user_id,
Expand All @@ -131,10 +144,15 @@ export class SchoolService {
country_code: school.country_code,
is_blocked: school.is_blocked,
created_at: school.created_at,
email: school.email
};
}

private toModel(school: SchoolDto): any {
private async toModel(school: SchoolDto): Promise<any> {
const emails = school.email ?
(Array.isArray(school.email) ? school.email : [school.email])
.filter(email => email) : [];

return {
user_id: school?.user_id || uuidv4(),
giga_id_school: school.giga_id_school?.toLowerCase().trim(),
Expand All @@ -144,6 +162,7 @@ export class SchoolService {
created: school.created,
ip_address: school.ip_address,
country_code: school.country_code,
};
email: emails
}
}
}