Add list moons command (#449)
- Add concept of moons to the database - Add the list moons command to view a user's moons - This command is paginated using buttons #195 Reviewed-on: #449 Reviewed-by: VylpesTester <tester@vylpes.com> Co-authored-by: Ethan Lane <ethan@vylpes.com> Co-committed-by: Ethan Lane <ethan@vylpes.com>
This commit is contained in:
parent
8e87fd6618
commit
e2ec042fcd
10 changed files with 235 additions and 3 deletions
49
src/database/entities/Moon.ts
Normal file
49
src/database/entities/Moon.ts
Normal file
|
@ -0,0 +1,49 @@
|
|||
import { Column, Entity, IsNull } from "typeorm";
|
||||
import BaseEntity from "../../contracts/BaseEntity";
|
||||
import AppDataSource from "../dataSources/appDataSource";
|
||||
|
||||
@Entity()
|
||||
export default class Moon extends BaseEntity {
|
||||
constructor(moonNumber: number, description: string, userId: string) {
|
||||
super();
|
||||
|
||||
this.MoonNumber = moonNumber;
|
||||
this.Description = description;
|
||||
this.UserId = userId;
|
||||
}
|
||||
|
||||
@Column()
|
||||
MoonNumber: number;
|
||||
|
||||
@Column()
|
||||
Description: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
WhenArchived?: Date;
|
||||
|
||||
@Column()
|
||||
UserId: string;
|
||||
|
||||
public static async FetchMoonsByUserId(userId: string): Promise<Moon[] | null> {
|
||||
const repository = AppDataSource.getRepository(Moon);
|
||||
|
||||
const all = await repository.find({ where: { UserId: userId } });
|
||||
|
||||
return all;
|
||||
}
|
||||
|
||||
public static async FetchPaginatedMoonsByUserId(userId: string, pageLength: number, page: number): Promise<[ Moon[], number ]> {
|
||||
const rangeStart = page * pageLength;
|
||||
|
||||
const repository = AppDataSource.getRepository(Moon);
|
||||
|
||||
const moons = await repository.findAndCount({
|
||||
where: { UserId: userId, WhenArchived: IsNull() },
|
||||
order: { MoonNumber: "ASC" },
|
||||
skip: rangeStart,
|
||||
take: pageLength,
|
||||
});
|
||||
|
||||
return moons;
|
||||
}
|
||||
}
|
15
src/database/migrations/3.3/1719856023429-CreateMoon.ts
Normal file
15
src/database/migrations/3.3/1719856023429-CreateMoon.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm"
|
||||
import MigrationHelper from "../../../helpers/MigrationHelper"
|
||||
|
||||
export class CreateMoon1719856023429 implements MigrationInterface {
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
MigrationHelper.Up('1719856023429-CreateMoon', '3.3.0', [
|
||||
"01-Moon",
|
||||
], queryRunner);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue