Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 5 additions & 5 deletions assets/jinja/tables/table.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ AnyPgColumn,
geometry,
index
} from "drizzle-orm/pg-core";
import { createdAt, updatedAt } from "../common";
import { createdAt, updatedAt, idReference, idColumn } from "../common";
{% for table in unique_tables %}
import { {{ table.dbName }}, {{table.pascalCase}}Keys } from "./{{ table.dbName }}";{% endfor %}
import {abbreviation} from "../abbreviation"
Expand All @@ -24,19 +24,19 @@ import { project } from "../project";
export const {{ table.dbName }} = pgTable(
"{{ table.dbName }}",
{
id: serial("id").primaryKey(),
id: idColumn(),
{% for column in table.columns if not column.isInherited %}
{{ column.camelCase }}: {{ column.dataType }}("{{ column.dbName }}"{% if column.dataType == 'timestamp' %},{mode : "date"}{%
{{ column.camelCase }}:{% if not column.isAbbreviation %}{{ column.dataType }}{% endif %}{% if column.isAbbreviation %}idReference{% endif %} ("{{ column.dbName }}"{% if column.dataType == 'timestamp' %},{mode : "date"}{%
endif %}){% if column.isAbbreviation %}.references((): AnyPgColumn => abbreviation.id){% endif %}{% if column.isRequired
%}.notNull(){% endif %},{% endfor %}
createdAt: createdAt(),
updatedAt: updatedAt(),
{% if table.parentTableDbName %}
{{ table.parentTableCamelCase }}Id: integer("{{ table.parentTableDbName }}_id")
{{ table.parentTableCamelCase }}Id: idReference("{{ table.parentTableDbName }}_id")
.references(() => {{ table.parentTableDbName }}.id, {onDelete : 'cascade'}).notNull(),
{% endif %}
{% if table.dbName == 'location_details' %}
projectId: integer("project_id").notNull().references((): AnyPgColumn => project.id),
projectId: idReference("project_id").notNull().references((): AnyPgColumn => project.id),
geometry: geometry('geometry', { type: 'point', mode: 'xy', srid: 4326 }),
{% endif %}

Expand Down
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { getProjectForUser } from "@/lib/dal/projects";
import { revalidateCustomTableCache } from "@/lib/dal/custom-tables";

export async function createCustomTableAction(
projectId: number,
folderId?: number | null,
projectId: string,
folderId?: string | null,
) {
const user = await getServerUser();
const userProject = await getProjectForUser(user, projectId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { getProjectForUser } from "@/lib/dal/projects";
import { revalidateCustomTableCache } from "@/lib/dal/custom-tables";

export async function deleteCustomTableAction(
projectId: number,
tableId: number,
projectId: string,
tableId: string,
) {
const user = await getServerUser();
const userProject = await getProjectForUser(user, projectId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { getProjectForUser } from "@/lib/dal/projects";
import { revalidateCustomTableCache } from "@/lib/dal/custom-tables";

export async function duplicateCustomTableAction(
projectId: number,
tableId: number,
projectId: string,
tableId: string,
) {
const user = await getServerUser();
const userProject = await getProjectForUser(user, projectId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { getProjectForUser } from "@/lib/dal/projects";
import { revalidateTag } from "next/cache";

export async function moveCustomTableAction(
projectId: number,
customTableId: number,
newFolderId: number | null,
projectId: string,
customTableId: string,
newFolderId: string | null,
) {
const user = await getServerUser();
const userProject = await getProjectForUser(user, projectId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { getProjectForUser } from "@/lib/dal/projects";
import { revalidateCustomTableCache } from "@/lib/dal/custom-tables";

export async function updateCustomTableAction(
projectId: number,
tableId: number,
projectId: string,
tableId: string,
data: { name: string },
) {
const user = await getServerUser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import { getProjectForUser } from "@/lib/dal/projects";
import { notFound } from "next/navigation";

export async function updateCustomTableDefinitionAction(
id: number,
id: string,
definition: CustomTableDefinition,
projectId: number,
projectId: string,
): Promise<void> {
const user = await getServerUser();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
} from "@/db/crud/zone";
import { readZones } from "@/db/crud/zone";
export async function updateCustomTableZones(
projectId: number,
tableId: number,
zoneIds: number[],
projectId: string,
tableId: string,
zoneIds: string[],
) {
const user = await getServerUser();
const userProject = await getProjectForUser(user, projectId);
Expand All @@ -36,15 +36,15 @@ export async function updateCustomTableZones(
!existingCustomTableZones.some((zone) => zone.zoneId === zoneId),
);

const zonesToDelete = existingZones.filter(
(zone) => !zoneIds.includes(zone.id),
const zonesToDelete = existingCustomTableZones.filter(
(zone) => !zoneIds.includes(zone.zoneId),
);

await Promise.all([
zonesToCreate.length > 0
? createCustomTableZones(tableId, zonesToCreate)
: Promise.resolve(),
...zonesToDelete.map((zone) => deleteCustomTableZone(tableId, zone.id)),
...zonesToDelete.map((zone) => deleteCustomTableZone(tableId, zone.zoneId)),
]);

revalidateCustomTableCache(tableId, projectId);
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/actions/data/folders/createFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { getProjectForUser } from "@/lib/dal/projects";
import { revalidateTag } from "next/cache";

export async function createFolderAction(
projectId: number,
parentFolderId: number | null = null,
projectId: string,
parentFolderId: string | null = null,
type: "customTable" | "plot" = "customTable",
name?: string,
) {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/actions/data/folders/deleteFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { deleteFolder, readFolder } from "@/db/crud/folder";
import { getProjectForUser } from "@/lib/dal/projects";
import { revalidateTag } from "next/cache";

export async function deleteFolderAction(projectId: number, folderId: number) {
export async function deleteFolderAction(projectId: string, folderId: string) {
const user = await getServerUser();
const userProject = await getProjectForUser(user, projectId);

Expand Down
6 changes: 3 additions & 3 deletions packages/app/src/actions/data/folders/moveFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { getProjectForUser } from "@/lib/dal/projects";
import { revalidateTag } from "next/cache";

export async function moveFolderAction(
projectId: number,
folderId: number,
newParentFolderId: number | null,
projectId: string,
folderId: string,
newParentFolderId: string | null,
) {
const user = await getServerUser();
const userProject = await getProjectForUser(user, projectId);
Expand Down
6 changes: 3 additions & 3 deletions packages/app/src/actions/data/folders/updateFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { getProjectForUser } from "@/lib/dal/projects";
import { revalidateTag } from "next/cache";

export async function updateFolderAction(
projectId: number,
folderId: number,
data: { name?: string; parentFolderId?: number | null },
projectId: string,
folderId: string,
data: { name?: string; parentFolderId?: string | null },
) {
const user = await getServerUser();
const userProject = await getProjectForUser(user, projectId);
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/actions/data/plots/createPlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { getProjectForUser } from "@/lib/dal/projects";
import { createPlot, generateUniquePlotName } from "@/db/crud/plot";

export async function createPlotAction(
projectId: number,
folderId?: number | null,
projectId: string,
folderId?: string | null,
) {
const user = await getServerUser();
const userProject = await getProjectForUser(user, projectId);
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/actions/data/plots/deletePlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { redirect } from "next/navigation";
import { getProjectForUser } from "@/lib/dal/projects";
import { revalidatePlotCache } from "@/lib/dal/plots";

export async function deletePlotAction(projectId: number, plotId: number) {
export async function deletePlotAction(projectId: string, plotId: string) {
const user = await getServerUser();
const userProject = await getProjectForUser(user, projectId);

Expand Down
6 changes: 3 additions & 3 deletions packages/app/src/actions/data/plots/movePlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { getProjectForUser } from "@/lib/dal/projects";
import { revalidateTag } from "next/cache";

export async function movePlotAction(
projectId: number,
plotId: number,
newFolderId: number | null,
projectId: string,
plotId: string,
newFolderId: string | null,
) {
const user = await getServerUser();
const userProject = await getProjectForUser(user, projectId);
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/actions/data/plots/updatePlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { PlotInsert } from "@common/db/schema/plot";
import { revalidatePlotCache } from "@/lib/dal/plots";

export async function updatePlotAction(
projectId: number,
plotId: number,
projectId: string,
plotId: string,
data: Pick<PlotInsert, "name">,
) {
const user = await getServerUser();
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/actions/data/plots/updatePlotDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { getProjectForUser } from "@/lib/dal/projects";
import { notFound } from "next/navigation";

export async function updatePlotDefinitionAction(
plotId: number,
plotId: string,
definition: PlotDefinition,
projectId: number,
projectId: string,
) {
const user = await getServerUser();

Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/actions/data/templates/applyTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import {
import { plotDefinitionSchema } from "@common/db/schema/plot";

type ApplyTemplateParams = {
projectId: number;
projectId: string;
customTableName: string;
customTableDefinition: CustomTableWithoutFilters;
plotName?: string;
plotDefinition?: PlotDefinitionWithoutSource;
folderId?: number | null;
folderId?: string | null;
};

export async function applyTemplateAction({
Expand Down
8 changes: 4 additions & 4 deletions packages/app/src/actions/data/templates/createTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ interface CreateTemplateParams {
name: string;
description?: string;
scope: "public" | "private";
customTableId?: number;
plotId?: number;
projectId: number;
tagIds?: number[];
customTableId?: string;
plotId?: string;
projectId: string;
tagIds?: string[];
}

export async function createTemplateAction({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { getCustomTableForProject } from "@/lib/dal/custom-tables";
import { readTagsWithUsageCountsByUserId } from "@/db/crud/tag";

export async function readCustomTableForTemplateAction(
projectId: number,
customTableId: number,
projectId: string,
customTableId: string,
) {
const user = await getServerUser();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { getPlotForProject } from "@/lib/dal/plots";
import { readTagsWithUsageCountsByUserId } from "@/db/crud/tag";

export async function readPlotForTemplateAction(
projectId: number,
plotId: number,
projectId: string,
plotId: string,
) {
const user = await getServerUser();

Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/actions/data/templates/readTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { getServerUser } from "@/lib/auth";
import { readTemplateWithTags } from "@/db/crud/template";

export async function readTemplateAction(templateId: number) {
export async function readTemplateAction(templateId: string) {
const user = await getServerUser();

const template = await readTemplateWithTags(templateId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type TemplateFilters = {
search?: string;
type?: "all" | "customTable" | "plot";
scope?: "all" | "public" | "private";
tagIds?: number[];
tagIds?: string[];
page?: number;
pageSize?: number;
};
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/actions/imports/ags/autoSaveAgsImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ if (!bucketName) {

export async function autoSaveAgsImport(
fileUpload: AgsFileUpload,
projectId: number,
importId: number,
projectId: string,
importId: string,
) {
const user = await getServerUser();

Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/actions/imports/ags/createImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { redirect } from "next/navigation";

export async function createImport(
blobsData: Omit<AgsFileUploadInsert, "agsImportId">[],
projectId: number,
projectId: string,
agsDictionaryVersion: AgsDictionaryVersion,
) {
const user = await getServerUser();
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/actions/imports/ags/deleteImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { getServerUser } from "@/lib/auth";
import { checkImportExistsForProject } from "@/db/crud/import";
import { revalidatePath } from "next/cache";
export async function deleteAgsImportAction(
importId: number,
projectId: number,
importId: string,
projectId: string,
) {
const user = await getServerUser();

Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/actions/imports/ags/executeImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { redirect } from "next/navigation";
import { revalidatePath } from "next/cache";

export async function completeExecuteImport(
importId: number,
projectId: number,
importId: string,
projectId: string,
) {
const user = await getServerUser();

Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/actions/imports/ags/validateImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { validateAgsData } from "@groundup-dev/ags";
import { redirect } from "next/navigation";

export async function completeValidateImport(
projectId: number,
importId: number,
projectId: string,
importId: string,
) {
const user = await getServerUser();

Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/actions/imports/csv/autoSaveCsvImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { revalidatePath } from "next/cache";

// The extractedData is typed as Record<TableName, Record<string, any>[]>
export async function autoSaveCsvImport(
projectId: number,
importId: number,
projectId: string,
importId: string,
tableName: TableName,
data: Record<string, unknown>[],
) {
Expand Down
Loading